cloud-functions-python icon indicating copy to clipboard operation
cloud-functions-python copied to clipboard

Cannot run handle_http example

Open manurueda opened this issue 7 years ago • 12 comments

Hi Martin,

First of all, congrats for the tool. It seems really promising!

I've been trying to run handle_http example, I get status: READY (everything goes fine, apparently) but get a 500 when I enter the resulting url. When I log to google cloud error reporting I got this error:

ImportError: No module named urlparse Failed to execute script function
at _import_module (site-packages/six.py:82)
at _resolve (site-packages/six.py:160)
at __get__ (site-packages/six.py:92)
at <module> (site-packages/cloudfn/http.py:5)
at load_module (/tmp/pip-build-QIE5nA/pyinstaller/PyInstaller/loader/pyimod03_importers.py:389)
at <module> (function.py:1)

My steps are: 1/ create files function.py, deploy.sh and requirements.txt 2/ create new virtualenv and install requirements 3/ launch deploy

I checked on the python console if I can import urlparse, or six.moves.urlib.parse and everything seems fine. I am running everything on python 2.7.

I am a bit lost, maybe you can help me.

manurueda avatar Sep 07 '17 12:09 manurueda

function.py

from cloudfn.http import Response, handle_http_event


def handle_http(req):
    return Response(
        status_code=200,
        body={'key': 2},
        headers={'content-type': 'application/json'},
    )


handle_http_event(handle_http)

requirements.txt

pycloudfn==0.1.205


deploy.sh

py-cloud-fn handle_http http -p -f function.py --python_version 2.7 && \
cd cloudfn/target && gcloud beta functions deploy handle_http \
--trigger-http --stage-bucket <MYBUCKET> --memory 2048MB && cd ../..

manurueda avatar Sep 07 '17 12:09 manurueda

Thanks, I'll have a look this weekend :D

MartinSahlen avatar Sep 07 '17 13:09 MartinSahlen

And please bear with me, this was created over a few jetlagged days in New York, it is very much alpha 😂

MartinSahlen avatar Sep 07 '17 13:09 MartinSahlen

Other examples work pretty well 💯

manurueda avatar Sep 11 '17 15:09 manurueda

@jmderueda I can't see your full trace, but might be the same issue I am having - my trace after deployed and tested is:

File "http_test.py", line 1, in File "/tmp/pip-build-1Vm687/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module File "site-packages/cloudfn/http.py", line 5, in File "site-packages/six.py", line 92, in get File "site-packages/six.py", line 160, in _resolve File "site-packages/six.py", line 82, in _import_module ImportError: No module named urlparse

I think it's an issue with using urlparse (from six) vs urlparse (built-in python). Both urlparse return the same object so I think we can use python's built-in safely.

@MartinSahlen maybe we can test this this change in http.py? Let me know if you're OK I can send another pull request for this change (I wasn't able to test because when deployed, requirements.txt does not seem to like git+git://xxxxx@branch) [edit] the fix will only work for python 2, with python 3 we would need a couple of more lines. If this is the issue, I will add to the fix.

Thanks

mrmacpholea avatar Sep 27 '17 23:09 mrmacpholea

Exactly! That is my problem. Thank you @marcelopham! ᐧ

On Thu, Sep 28, 2017 at 1:21 AM, marcelopham [email protected] wrote:

@jmderueda https://github.com/jmderueda I can't see your full trace, but might be the same issue I am having - my trace after deployed and tested is:

File "http_test.py", line 1, in File "/tmp/pip-build-1Vm687/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module File "site-packages/cloudfn/http.py", line 5, in File "site-packages/six.py", line 92, in get File "site-packages/six.py", line 160, in _resolve File "site-packages/six.py", line 82, in _import_module ImportError: No module named urlparse

I think it's an issue with using urlparse (from six) vs urlparse (built-in python). Both urlparse return the same object so I think we can use python's built-in safely.

@MartinSahlen https://github.com/martinsahlen maybe we can test this this change in http.py https://github.com/marcelopham/cloud-functions-python/commit/a88e3722c7f24e7d1b9f6ca0d9a581f9d1d90aa2? Let me know if you're OK I can send another pull request for this change (I wasn't able to test because when deployed, requirements.txt does not seem to like git+git://xxxxx@branch)

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MartinSahlen/cloud-functions-python/issues/17#issuecomment-332682859, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKgrgze8X9KUOLcFBAf7y7swrfK7Juyks5smthygaJpZM4PPuy_ .

manurueda avatar Sep 27 '17 23:09 manurueda

Just wondering if this (not using six) will break compatibility with python2+3?

MartinSahlen avatar Sep 28 '17 13:09 MartinSahlen

Not sure

El 28 sept. 2017 3:29 p. m., "Martin Abelson Sahlen" < [email protected]> escribió:

Just wondering if this (not using six) will break compatibility with python2+3?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MartinSahlen/cloud-functions-python/issues/17#issuecomment-332836470, or mute the thread https://github.com/notifications/unsubscribe-auth/ADKgrsdG8Ge_B0ZQ8ECuIxg4BHbmzJuNks5sm59QgaJpZM4PPuy_ .

manurueda avatar Sep 28 '17 13:09 manurueda

As far as my understanding goes, six is a compatibility layer that makes sure that code works on both python 2 and 3 where stuff is deprecated or changed? I'll look some more into this.

MartinSahlen avatar Sep 28 '17 15:09 MartinSahlen

We could do something like:

try: from six.moves.urllib_parse import urlparse except ImportError: from urlparse import urlparse

mrmacpholea avatar Sep 28 '17 16:09 mrmacpholea

@MartinSahlen @marcelopham I can confirm the change in http.py of

from six.moves.urllib_parse import urlparse to from urlparse import urlparse

change worked for me using python 2.7. Though because py-cloud-fn pulls its requirements from pip at build time, I had to manually edit the site-packages within the cloudfn directory and recompile the python .pyc file before deploying.

davidbernat avatar Nov 05 '17 23:11 davidbernat

Hi,

Trying for the first time the repo and got the same error. Any progress on this topic ? I'm using Python 2.7.

What are the issues using the default urlparse lib instead of the one provided by six ?

Thanks @davidbernat, your steps description worked for me as well.

Thanks

JulienD avatar Jan 25 '18 11:01 JulienD