Error: class uri 'eventlet' invalid or not found
Asked Answered
R

4

21

I've been running a dockerized flask application that uses Celery to run tasks. To run the app I'm using gunicorn with eventlet and It's been working fine using alpine linux distribution.

However I had to move to ubuntu due to some issues with sklearn and other libraries, and now I'm having problems to run my app.

First of all I'm getting this error:

Error: class uri 'eventlet' invalid or not found:

[Traceback (most recent call last):
  File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 11, in <module>
    import eventlet
ModuleNotFoundError: No module named 'eventlet'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/myapp/env/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
    mod = import_module('.'.join(components))
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 13, in <module>
    raise RuntimeError("You need eventlet installed to use this worker.")
RuntimeError: You need eventlet installed to use this worker.

Then I tried by adding pip install eventlet to my app's Dockerfile, and now I have this another error:

Error: class uri 'eventlet' invalid or not found:

[Traceback (most recent call last):
  File "/myapp/env/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
    mod = import_module('.'.join(components))
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/myapp/env/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 11, in <module>
    import eventlet
  File "/myapp/env/lib/python3.6/site-packages/eventlet/__init__.py", line 10, in <module>
    from eventlet import convenience
  File "/myapp/env/lib/python3.6/site-packages/eventlet/convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "/myapp/env/lib/python3.6/site-packages/eventlet/green/socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "/myapp/env/lib/python3.6/site-packages/eventlet/support/greendns.py", line 69, in <module>
    setattr(dns.rdtypes.IN, pkg, import_patched('dns.rdtypes.IN.' + pkg))
  File "/myapp/env/lib/python3.6/site-packages/eventlet/support/greendns.py", line 59, in import_patched
    return patcher.import_patched(module_name, **modules)
  File "/myapp/env/lib/python3.6/site-packages/eventlet/patcher.py", line 126, in import_patched
    *additional_modules + tuple(kw_additional_modules.items()))
  File "/myapp/env/lib/python3.6/site-packages/eventlet/patcher.py", line 100, in inject
    module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
  File "/myapp/env/lib/python3.6/site-packages/dns/rdtypes/IN/WKS.py", line 25, in <module>
    _proto_tcp = socket.getprotobyname('tcp')
OSError: protocol not found

This is how I start my app (start.sh):

gunicorn -w 1 --worker-class eventlet --certfile=myapp/myapp.crt --keyfile=myapp/myapp.key --bind 0.0.0.0:5000 --log-config myapp/gunicorn.conf myapp.run:app

It's been working fine until I moved to an ubuntu based container.

What am I missing here?

I appreciate any help.

Thanks!

Roesch answered 28/10, 2019 at 10:19 Comment(0)
A
29

I had the same issue, and I found that it is caused by some updates made by eventlet they removed eventlet.wsgi.ALREADY_HANDLED but gunicorn is still using it. So , you better downgrade the eventlet version.

pip install gunicorn==20.1.0 eventlet==0.30.2

Here is a reference https://github.com/eventlet/eventlet/issues/702

Anesthetize answered 15/7, 2021 at 19:11 Comment(3)
Beware, that this will not work with Python 3.10. Make sure to specify python version by adding a file called runtime.txt with the text "python-3.9.13". That worked for me.Tubular
I use poetry. pyproject.toml: python = "3.8.1" gunicorn = {extras = ["eventlet==0.30.2"], version = "^20.1.0"} but error: ImportError: cannot import name 'ALREADY_HANDLED' from 'eventlet.wsgi'Betrothal
@BluePrint Why won't it work in 3.10?Abed
S
2

I tried for a lot and finally working, please check these:

If u are using heroku, edit the requeriments.txt adding gunicorn and eventlet version and also edit runtime.txt with "python-3.9.13" (In case you are using heroku stack 22). If you are running another heroku stack, please check it's python compatible versions. (source = https://devcenter.heroku.com/articles/python-support#supported-runtimes)

Samoyedic answered 8/11, 2022 at 17:6 Comment(1)
just be aware of this security issueDowell
R
1

I'll post the solution I've found in case it's useful to anyone.

Just I was missing the /etc/protocols, and this is how I've fixed it:

I had to add this step in my Dockerfile:

RUN apt-get -o Dpkg::Options::='--force-confmiss' install --reinstall -y netbase

Roesch answered 28/10, 2019 at 11:21 Comment(1)
I am facing the same problem, but this does not resolves my issue. I am running this command. gunicorn app.instance:app --worker-class eventlet -w 1 --bind 0.0.0.0:5000 --reload. Any help would be appreciated.Illtreat
A
0

Just want to add on to the discussion too that after facing the same issues, here's the working set of modules for me:

dnspython==2.4.2
eventlet==0.34.3
Flask==2.0.3
Flask-SocketIO==4.3.1
gunicorn==21.2.0

My runtime.txt

python-3.8.18

My Procfile

web: gunicorn -k eventlet app:app

Within first few lines of my app.py file

import eventlet
eventlet.monkey_patch(socket=True)

And using Heroku-20 stack.

Araldo answered 15/1, 2024 at 0:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.