2015-03-13 53 views
0

我嘗試使用gevent.socketio與我的TurboGears 2網址:的TurboGears與GEVENT-socketio:請求鍵錯誤

在ini文件我用

[server:main] 
use = egg:gevent-socketio#paster 
transports = xhr-multipart, xhr-polling, websocket 
host = 0.0.0.0 
port = 8080 

當我嘗試訪問控制器在web瀏覽器:

@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模塊,但總是出現同樣的錯誤。 我是相當新的插座,所以也許我只是失去了一些東西明顯

回答

0

的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) 
+0

這就是爲什麼在https://github.com/amol-/tgext.socketio實例安裝在'socketio'路徑'socket.io'控制器的原因。如果你想實際上將它作爲'/ socket.io'來提供,你可以使用'app_cfg.py'中的'disable_request_extensions'和'dispatch_path_translator'選項來實現它。 – amol 2015-03-15 22:01:08