我想使用python连接到Socket.IO服务器.有办法吗?
我websocket-client按照这个答案的建议尝试过.
ws = create_connection("ws://example.com:1000/socket.io/")
Run Code Online (Sandbox Code Playgroud)
该代码抛出此异常
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
Run Code Online (Sandbox Code Playgroud)
我觉得我缺少参数,因为JS客户端连接URL如下所示:
ws://example.com:1000/socket.io/?EIO=3&transport=websocket&sid=CHARSANDNUMBERS
Run Code Online (Sandbox Code Playgroud) 我使用安装了twisted和Autobahn websocket
pip install twisted
pip install autobahn
Run Code Online (Sandbox Code Playgroud)
但是当我从Autobahn导入任何工厂时,我得到了无法导入名称的错误.
>>> from twisted.internet import reactor
>>> from autobahn.websocket import WebSocketClientFactory
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name WebSocketClientFactory
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?这是冻结点
Twisted==13.2.0
Twisted-Core==12.3.0
Twisted-Names==12.3.0
Twisted-Web==12.3.0
autobahn==0.7.4
websocket==0.2.1
websocket-client==0.13.0
Run Code Online (Sandbox Code Playgroud)