简体   繁体   English

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

[英]Heroku Flask Socketio cannot import name 'namespace'

Error: 错误:

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

code: https://github.com/ncd2dq/nickdima_site/tree/master/nickdima I've added the comment #CAUSES PROBLEM above all lines of code that are in question. 代码: https : //github.com/ncd2dq/nickdima_site/tree/master/nickdima我在所有有问题的代码行上方添加了注释#CAUSES PROBLEM。 It's only where ever I'm trying to import flask_socketio. 这只是我尝试导入flask_socketio的地方。 The Only files that are relevant in my repo are nickdima> init .py and nickdima>test_pong>pong.py 与我的仓库相关的唯一文件是nickdima> init .py和nickdima> test_pong> pong.py

I do not have any files / folders in my project with "socketio" in their name. 我的项目中没有名称为“ socketio”的文件/文件夹。

I've been trying to get Flask-Socketio to work for sometime now, see my other open question here ( Flask-Socketio takes extremely long to connect on Heroku ) and in trying to solve that issue I've somehow caused the below error (from heroku logs): 我一直在尝试让Flask-Socketio正常工作一段时间,在这里查看我的另一个未解决的问题( Flask-Socketio在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

In my troubleshooting I was switching back and forth between guinicorn versions as well as iinstalling/uninstalling gevent/eventlet 在我的疑难解答中,我在guinicorn版本以及iinstall / uninstall gevent / eventlet之间来回切换

Here's my current requirements.txt file: 这是我当前的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

Ah-Ha! 啊,哈!

Turns out yesterday when I was switching between eventlet/gevent, Heroku's dependency cache was storing both eventlet/gevent even when I would remove them from my requirements.txt and it would say "uninstalling gevent" or "uninstalling eventlet". 昨天的结果是,当我在eventlet / gevent之间切换时,Heroku的依赖项缓存同时存储了eventlet / gevent,即使我将它们从我的requirements.txt中删除,它也会显示“正在卸载gevent”或“正在卸载eventlet”。 This caused the issue. 这引起了问题。

To clear the cache I changed my python runtime based on this: https://devcenter.heroku.com/articles/python-runtimes 为了清除缓存,我根据以下内容更改了python运行时: https : //devcenter.heroku.com/articles/python-runtimes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM