带有 gevent-socketio 的 Turbogears:请求密钥错误
Turbogears with gevent-socketio: request Key Error
我尝试在我的 TurboGears 2 网站上使用 gevent.socketio:
在我使用的 ini 文件中
[server:main]
use = egg:gevent-socketio#paster
transports = xhr-multipart, xhr-polling, websocket
host = 0.0.0.0
port = 8080
当我尝试访问网络浏览器中的控制器时:
@expose('wago.templates.test')
def index(self):
socketio_manage(request.environ, {"/stat": StatNamespace}, request=request)
return dict()
我收到以下错误:
Traceback (most recent call last):
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/wsgiapp.py", line 105, in __call__
response = self.wrapped_dispatch(controller, environ, context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/wsgiapp.py", line 278, in dispatch
return controller(environ, context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/dispatcher.py", line 132, in __call__
response = self._perform_call(context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/dispatcher.py", line 113, in _perform_call
r = self._call(func, params, remainder=remainder, context=context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/decoratedcontroller.py", line 120, in _call
output = controller_caller(context_config, bound_controller_callable, remainder, params)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/decorators.py", line 42, in _decorated_controller_caller
return application_controller_caller(tg_config, controller, remainder, params)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/configuration/app_config.py", line 124, in call_controller
return controller(*remainder, **params)
File "/home/pi/tgenv/WAGO/wago/controllers/root.py", line 13, in index
socketio_manage(request.environ, {"/stat": StatNamespace}, request=request)
File "/home/pi/tgenv/lib/python2.7/site-packages/socketio/__init__.py", line 67, in socketio_manage
socket = environ['socketio']
KeyError: 'socketio'
我使用了几个金字塔教程来介绍自己的gevent-socketio。
我尝试使用 TurboGears2、gevent 和 gevent-socketio 的旧版本,我也尝试了 this 模块,但总是出现相同的错误。
我对套接字很陌生,所以也许我只是遗漏了一些明显的东西
gevent-socketio 仅识别来自特定 url (socket.io/1/) 的套接字请求
因为 TurboGears 使用 python 函数名称作为 url 它对我们来说是不可能的 "."或常规方式为“1”。一个简单的解决方案:
@expose()
def _default(self, *args):
args = list(args)
if "socketio" in request.environ:
#do socketio stuff...
else:
abort(404)
我尝试在我的 TurboGears 2 网站上使用 gevent.socketio:
在我使用的 ini 文件中
[server:main]
use = egg:gevent-socketio#paster
transports = xhr-multipart, xhr-polling, websocket
host = 0.0.0.0
port = 8080
当我尝试访问网络浏览器中的控制器时:
@expose('wago.templates.test')
def index(self):
socketio_manage(request.environ, {"/stat": StatNamespace}, request=request)
return dict()
我收到以下错误:
Traceback (most recent call last):
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/wsgiapp.py", line 105, in __call__
response = self.wrapped_dispatch(controller, environ, context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/wsgiapp.py", line 278, in dispatch
return controller(environ, context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/dispatcher.py", line 132, in __call__
response = self._perform_call(context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/dispatcher.py", line 113, in _perform_call
r = self._call(func, params, remainder=remainder, context=context)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/controllers/decoratedcontroller.py", line 120, in _call
output = controller_caller(context_config, bound_controller_callable, remainder, params)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/decorators.py", line 42, in _decorated_controller_caller
return application_controller_caller(tg_config, controller, remainder, params)
File "/home/pi/tgenv/lib/python2.7/site-packages/tg/configuration/app_config.py", line 124, in call_controller
return controller(*remainder, **params)
File "/home/pi/tgenv/WAGO/wago/controllers/root.py", line 13, in index
socketio_manage(request.environ, {"/stat": StatNamespace}, request=request)
File "/home/pi/tgenv/lib/python2.7/site-packages/socketio/__init__.py", line 67, in socketio_manage
socket = environ['socketio']
KeyError: 'socketio'
我使用了几个金字塔教程来介绍自己的gevent-socketio。 我尝试使用 TurboGears2、gevent 和 gevent-socketio 的旧版本,我也尝试了 this 模块,但总是出现相同的错误。 我对套接字很陌生,所以也许我只是遗漏了一些明显的东西
gevent-socketio 仅识别来自特定 url (socket.io/1/) 的套接字请求 因为 TurboGears 使用 python 函数名称作为 url 它对我们来说是不可能的 "."或常规方式为“1”。一个简单的解决方案:
@expose()
def _default(self, *args):
args = list(args)
if "socketio" in request.environ:
#do socketio stuff...
else:
abort(404)