Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Syntax error in module 'handler': invalid syntax (uuid.py, line 138) #1189

Closed robomotic closed 6 years ago

robomotic commented 6 years ago

I am using Zappa + Flask within Python 3.6 , the app involves updating a file to S3 bucket . I am using this to generate a unique file id:

destination_filename = uuid4().hex + source_extension

In my requriments I am using this version: uuid==1.30

Expected Behavior

The Flask app works as expected from the local python virtual environment.

Actual Behavior

After I do Zappa deploy on the AWS , I obtain an Internal Server Error when I visit the URL and from the zappa Logs I observe this error:

[1508769179023] 'NoneType' object is not callable [1508769293231] Syntax error in module 'handler': invalid syntax (uuid.py, line 138)

Possible Fix

No idea.

Steps to Reproduce

Use the UUID to produce a serial number.

Your Environment

argcomplete==1.9.2 awscli==1.11.175 base58==0.2.4 boto==2.48.0 boto3==1.4.7 botocore==1.7.33 certifi==2017.7.27.1 chardet==3.0.4 click==6.7 colorama==0.3.7 docutils==0.14 dominate==2.3.1 durationpy==0.5 Flask==0.12.2 flask-appconfig==0.11.1 Flask-Bootstrap==3.3.7.1 Flask-WTF==0.14.2 future==0.16.0 futures==3.1.1 hjson==3.0.0 idna==2.6 itsdangerous==0.24 Jinja2==2.9.6 jmespath==0.9.3 kappa==0.6.0 lambda-packages==0.16.1 MarkupSafe==1.0 placebo==0.8.1 pyasn1==0.3.7 python-dateutil==2.6.1 python-slugify==1.2.4 PyYAML==3.12 requests==2.18.4 rsa==3.4.2 s3transfer==0.1.11 six==1.11.0 toml==0.9.2 tqdm==4.15.0 troposphere==2.0.1 Unidecode==0.4.21 urllib3==1.22 uuid==1.30 visitor==0.1.3 Werkzeug==0.12 wsgi-request-logger==0.4.6 WTForms==2.1 zappa==0.44.3

Miserlou commented 6 years ago

Zappa uses the python stdlib uuid. You probably don't need uuid in your virtualenvironment. This isn't a Zappa bug.

robomotic commented 6 years ago

Thanks for the fast response, does that mean I don't have to include uuid? Is there a list where I can see what packages I am not allowed to put in the requirements list?

Miserlou commented 6 years ago

That's not really possible due to the nature of Python. But on all versions of python in recent memory, you should be able to pip uninstall uuid and still be able to import uuid without any issues. The issue is in your application.

robomotic commented 6 years ago

Got it yes is working now . Cheers!

mbourgon commented 6 years ago

@robomotic Exact same error with line 138 of UUID. Do you remember what you did to fix this? Thanks!

scoates commented 6 years ago

Have you tried doing what @Miserlou suggested above?

mbourgon commented 6 years ago

Yup. At this point it's definitely outside what y'all are doing here, so no worries if it's not blindingly obvious. Removed the uuid-1.30-py3.6.egg-info folder, created a new zip for the lambda code, uploaded it, tried invoking the lambda again, same error.

This is probably the code having an issue[...] def handler(event, context): bucket = event['Records'][0]['s3']['bucket']['name'] key = event['Records'][0]['s3']['object']['key'] download_path = '/tmp/{}{}'.format(uuid.uuid4(), key) [...]

Syntax error in module 'app': invalid syntax (uuid.py, line 138)

aakankshaduggal commented 5 years ago

pip uninstall uuid

It'll be fine.