(tornadio2)失败:WebSocket握手期间出错:意外响应代码:403

Oza*_*zan 5 python sockets tornado socket.io

当我在我的电脑上运行我的代码并尝试在localhost上连接socket与我的index.html没有问题,但当我尝试在服务器上运行我的代码并尝试连接socket与index.html(它位于我的电脑上)我得到:

Router <tornadio2.session.ConnectionInfo object at 0x7f7bfc5fac10>
INFO:tornado.access:200 GET /socket.io/1/
DEBUG:root:Initializing websocket handler.
WARNING:tornado.access:403 GET /socket.io/1/websocket/c0532cea9001408c50a9c854f4bce5d8
Run Code Online (Sandbox Code Playgroud)

然后它将protocal切换到xhr-polling但我想使用websocket.

INFO:tornado.access:200 GET /socket.io/1/xhr-polling/62f9b31662c984201685a830c764765e
DEBUG:root:Initializing xhr-polling transport.
DEBUG:root:>>> 1::/socket
DEBUG:root:<<< 1::/socket
DEBUG:root:<<< 3::/socket:connected!
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决这个问题?

Ben*_*ell 19

必须从与websocket相同的服务器加载html,除非您覆盖check_origin以允许跨源访问:http://www.tornadoweb.org/en/stable/websocket.html#tornado.websocket.WebSocketHandler.check_origin