[ERROR] ModuleNotFoundError: No module named 'werkzeug._compat'

Hi team,

I have create a sample Flask API app and deployed it using aws keys.
I did this following instructions on this page:
https://app.serverless.com/?package=aws-python-flask-api

Deployed it from the command-line on my machine - but now when I try accessing the published endpoints I am getting:

{“message”: “Internal server error”}

I went into the CloudWatch for the app see the following error:

[ERROR] ModuleNotFoundError: No module named 'werkzeug._compat'
Traceback (most recent call last):
  File "/var/task/serverless_sdk/__init__.py", line 144, in wrapped_handler
    return user_handler(event, context)
  File "/var/task/s_api.py", line 25, in error_handler
    raise e
  File "/var/task/s_api.py", line 20, in <module>
    user_handler = serverless_sdk.get_user_handler('wsgi_handler.handler')
  File "/var/task/serverless_sdk/__init__.py", line 56, in get_user_handler
    user_module = import_module(user_module_name)
  File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/wsgi_handler.py", line 22, in <module>
    import serverless_wsgi
  File "/var/task/serverless_wsgi.py", line 18, in <module>
    from werkzeug._compat import BytesIO, string_types, to_bytes, wsgi_encoding_dance

I read the documentation and seem that the package werkzeug may be missing - but it is required only when running serverless on a machine - but should work without it when deployed serverless.

Any ideas?

I did include werkzeug into requirements.txt - but still doesn’t help - I get the same error.

Any ideas?

Thanks!

This is an issue currently with the serverless-wsgi plugin used to deploy Serverless applications that has since been resolved by the plugin author.You can find more information here: Werkzeug updated. Getting errors · Issue #179 · logandk/serverless-wsgi · GitHub

Thanks for the reply! Looks like this was driven by python 2 compatibility issues. Btw since I posted my question I managed to resolve it by changing Flask version in the requirements.txt to
Flask==1.1.4
and removing werkzeug from it altogether.

Thanks for your reply anyway!

Hello, I’m just new to serverless and I just managed to get Python installed on Microsoft code.
Now I’ve connected my pyboard 1.1 and try to run a default program.
The first error I hit is: ModuleNotFoundError: No module named ‘pyb’

I hope someone can help solve this? Thanks.