我的目标是将应用程序从python2升级到python3。该应用程序使用以下包:flask, flask-admin, gevent(协程),socketio。弗拉斯克决定离开,其余的包裹也要重新装上。已经有几次尝试替换包:
- Tornado + SockJS:由于缺少SockJS而产生了大量的额外代码频道
- Flask-aiohttp:授权期间请求。form['username']抛出错误:
回溯(最近一次调用):
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/app.py",line 1381, in handle_user_exception reraise(exc_type, exc_value, tb)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/_compat.py",line 33, in reraise raise value
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/app.py",line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args)
File "/home/user/workspace/aiolina/aiolina.py", line 33, in login username = request.form['username']
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/utils.py", line 71, in __get__
value = self.func(obj)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/wrappers.py", line 488, in form
self._load_form_data()
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/flask/wrappers.py", line 165, in _load_form_data
RequestBase._load_form_data(self)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/wrappers.py", line 360, in _load_form_data
mimetype, content_length, options)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/formparser.py", line 193, in parse
content_length, options)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/formparser.py", line 103, in wrapper
exhaust()
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/wsgi.py", line 977, in exhaust
self.read(chunk)
File "/home/user/.env/rbaio34/lib/python3.4/site-packages/werkzeug/wsgi.py", line 994, in read
if to_read and len(read) != to_read:TypeError: object of type 'generator' has no len()
那么,可以对Flask-aiohttp工作做些什么呢?或者用什么包代替?
flask -aiohttp不是flask的临时替代品:通常它可以工作,但有时会产生像您所观察到的错误。
我建议只尝试aiohttp。第三方库SockJS支持SockJS
这个问题已经过时了,但在谷歌搜索结果列表中排名第一。所以我把它放在这里:
如果你正在寻找asyncio
兼容的插入式Flask替代品,那么你可能想看看Quart。它的目的是作为一个(几乎)直接的替代品,它甚至支持Flask扩展。