Heroku Flask Socketio无法导入名称“名称空间”

时间:2018-09-03 16:14:20

标签: python heroku flask flask-socketio

错误:

from socketio import Namespace as _Namespace
ImportError: cannot import name 'Namespace'

代码:https://github.com/ncd2dq/nickdima_site/tree/master/nickdima 我已在所有有问题的代码行上方添加了注释#CAUSES PROBLEM。这只是我尝试导入flask_socketio的地方。 我回购中唯一相关的文件是nickdima> init .py和nickdima> test_pong> pong.py

我的项目中没有名称为“ socketio”的文件/文件夹。

我一直在尝试让Flask-Socketio正常工作一段时间,请在此处查看我的另一个未解决的问题(Flask-Socketio takes extremely long to connect on Heroku),并在尝试解决该问题时以某种方式导致了以下错误(来自heroku)日志):

2018-09-03T16:07:40.660720+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Starting gunicorn 19.9.0
2018-09-03T16:07:40.661314+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Listening at: http://0.0.0.0:54684 (4)
2018-09-03T16:07:40.667073+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [8] [INFO] Booting worker with pid: 8
2018-09-03T16:07:40.661426+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Using worker: eventlet
2018-09-03T16:07:41.193765+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [8] [ERROR] Exception in worker process
2018-09-03T16:07:41.193787+00:00 app[web.1]: Traceback (most recent call last):
2018-09-03T16:07:41.193789+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-09-03T16:07:41.193791+00:00 app[web.1]: worker.init_process()
2018-09-03T16:07:41.193793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 102, in init_process
2018-09-03T16:07:41.193794+00:00 app[web.1]: super(EventletWorker, self).init_process()
2018-09-03T16:07:41.193796+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-09-03T16:07:41.193797+00:00 app[web.1]: self.load_wsgi()
2018-09-03T16:07:41.193799+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-09-03T16:07:41.193800+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-09-03T16:07:41.193802+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-09-03T16:07:41.193803+00:00 app[web.1]: self.callable = self.load()
2018-09-03T16:07:41.193805+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-09-03T16:07:41.193806+00:00 app[web.1]: return self.load_wsgiapp()
2018-09-03T16:07:41.193807+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-09-03T16:07:41.193809+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-09-03T16:07:41.193812+00:00 app[web.1]: __import__(module)
2018-09-03T16:07:41.193810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2018-09-03T16:07:41.193813+00:00 app[web.1]: File "/app/nickdima/wsgi.py", line 5, in <module>
2018-09-03T16:07:41.193815+00:00 app[web.1]: from __init__ import create_app
2018-09-03T16:07:41.193818+00:00 app[web.1]: from flask_socketio import SocketIO
2018-09-03T16:07:41.193816+00:00 app[web.1]: File "/app/nickdima/__init__.py", line 5, in <module>
2018-09-03T16:07:41.193819+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_socketio/__init__.py", line 23, in <module>
2018-09-03T16:07:41.193820+00:00 app[web.1]: from .namespace import Namespace
2018-09-03T16:07:41.193822+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_socketio/namespace.py", line 1, in <module>
2018-09-03T16:07:41.193823+00:00 app[web.1]: from socketio import Namespace as _Namespace
2018-09-03T16:07:41.193825+00:00 app[web.1]: ImportError: cannot import name 'Namespace'
2018-09-03T16:07:41.194220+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-09-03T16:07:41.266303+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [4] [INFO] Shutting down: Master
2018-09-03T16:07:41.266389+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-09-03T16:07:41.411382+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-03T16:07:41.393418+00:00 heroku[web.1]: Process exited with status 3
2018-09-03T16:07:42.980487+00:00 heroku[router]: at=error code=H10 desc="App cr

在故障排除中,我在guinicorn版本以及iinstall / uninstall gevent / eventlet之间来回切换

这是我当前的requirements.txt文件:

click==6.7
dnspython==1.15.0
eventlet==0.24.1
Flask==1.0.2
Flask-SocketIO==3.0.1
greenlet==0.4.14
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1

1 个答案:

答案 0 :(得分:0)

啊哈!

昨天的结果是,当我在eventlet / gevent之间切换时,Heroku的依赖项缓存同时存储了eventlet / gevent,即使我将它们从我的requirements.txt中删除,它也会显示“正在卸载gevent”或“正在卸载eventlet”。这引起了问题。

要清除缓存,我根据以下内容更改了python运行时: https://devcenter.heroku.com/articles/python-runtimes