Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: class uri 'eventlet' invalid or not found

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!

like image 645
magnoz Avatar asked Oct 28 '19 10:10

magnoz


2 Answers

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

like image 109
Mwibutsa Floribert Avatar answered Oct 27 '22 04:10

Mwibutsa Floribert


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

like image 45
magnoz Avatar answered Oct 27 '22 06:10

magnoz