我正在尝试搭建一个处理HTTP和socketio请求的小型服务器 - 我没有太多设置服务器的经验,但现在apache2可以很好地服务HTTP请求。然而,socketio事务会出现400错误代码(坏请求),在服务器日志中我看到一些奇怪的错误。有时我会看到engineio错误并且服务器会用“坏请求”和代码400响应,但总是告诉我需要启动eventlet服务器:
[Mon Jan 11 19:02:54.068282 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473] return ws(environ, start_response)
[Mon Jan 11 19:02:54.068305 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473] File "/var/www/projectENV/lib/python2.7/site-packages/engineio/async_eventlet.py", line 10, in __call__
[Mon Jan 11 19:02:54.068342 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473] raise RuntimeError('You need to use the eventlet server.')
[Mon Jan 11 19:02:54.068380 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473] RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.
[Mon Jan 11 19:02:54.253124 2016] [:error] [pid 4909:tid 140274940458752] WARNING:engineio:Invalid session cde3f9aadbee4794bf9d7bb98d0b396e
我的服务器代码很基本:
from flask import Flask
import flaskext.couchdb
from flask.ext.socketio import SocketIO
# for socketio
import eventlet
eventlet.monkey_patch()
# creation of server & db objects
app = Flask(__name__)
# socketio initialization
socketio = SocketIO(app, async_mode='eventlet')
# import views once site properties are set
from app import views
if __name__== "__main__":
socketio.run(app, debug=True)
我的客户端代码使用 Python 编写,直接从文档中使用 socketio-client 库:
from socketIO_client import SocketIO, LoggingNamespace
with SocketIO(SERVER_URL, 80, LoggingNamespace) as socketIO:
socketIO.emit('aaa')
socketIO.wait(seconds=1)
socketio.run(app)
不应该为我启动eventlet服务器吗?为什么服务器有时会返回错误请求?