错误:类uri'eventlet'无效或未找到

时间:2019-10-28 10:19:38

标签: python docker celery gunicorn flask-socketio

我一直在运行一个使用Celery运行任务的dockerized flask应用程序。 为了运行该应用程序,我使用带有eventlet的gunicorn,并且使用alpine linux发行版运行良好。

但是由于sklearn和其他库的某些问题,我不得不移至ubuntu,现在我在运行应用程序时遇到问题。

首先,我遇到此错误:

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.

然后我尝试通过将pip install eventlet添加到应用程序的Dockerfile中,现在又遇到了另一个错误:

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

这是我启动应用程序(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

在我移至基于ubuntu的容器之前,它一直运行良好。

我在这里想念什么?

感谢您的帮助。

谢谢!

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我发现它是由 eventlet 进行的一些更新引起的,他们删除了 eventlet.wsgi.ALREADY_HANDLED,但 gunicorn 仍在使用它。所以,你最好降级 eventlet 版本。

pip install gunicorn==20.1.0 eventlet==0.30.2

这是参考https://github.com/eventlet/eventlet/issues/702

答案 1 :(得分:0)

我将发布找到的解决方案,以防对任何人有用。

我只是想念/etc/protocols,这就是我的解决方法:

我必须在我的Dockerfile中添加此步骤:

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