【发布时间】:2014-04-03 13:48:44
【问题描述】:
我正在使用高速公路库在 python 中将 websocket 连接到 nodejs 服务器。我必须更改连接的标头和原始参数,但它给了我错误
factory.setSessionParameters(url="wss://xyz.com",origin='54:53:ed:29:23:85',protocols=['ovrc-protocol'],useragent=None,headers={'name':'ravi'})
TypeError: setSessionParameters() got an unexpected keyword argument 'headers'
我什至尝试保存关键字中的值并将这些关键字作为参数传递给 setSessionfatory 方法
url= "wss://xyz.com:1443"
headers = { 'Sec-WebSocket-Key':'uRovscZjNol/umbTt5uKmw==' }
origin='50:50:ed:27:21:33'
protocols=['wxyz-protocol']
useragent=None
factory.setProtocolOptions(version=13,utf8validateIncoming=False)
factory.setSessionParameters(url,origin,protocols,useragent,headers)
然后它返回错误,说方法 setSessionParameters 接受 5 个参数,提供 6 个参数
显然只有 5 个参数。我正在关注这个链接的方法 http://autobahn.ws/python/websocketclient.html 它有 setSessionParameters 的详细信息及其实际文档,但它根本不起作用。
如果可能,请建议我更简单的方法在 python 中进行 websocket 连接,我可以更改 websocket 参数,如源和 sec-WebSocket-key 值等。
谢谢
【问题讨论】:
-
这和宣传的一样有效,甚至还有一个例子:github.com/tavendo/AutobahnPython/tree/master/examples/twisted/… - 您可能正在经营一条旧高速公路?
-
感谢 oberstet,因为我为 apt-get 安装了高速公路,它确实安装了旧版本。感谢您指出。
-
我遇到了另一个问题,连接过早关闭,说收到的消息连接关闭不干净(无)..
-
您的服务器是否接受您宣布的子协议?另外:您在上面提供的
origin(54:53:ed:29:23:85) 无效。这需要是一个有效的 HTTP(S) URL(见这里tools.ietf.org/html/rfc6454)。也许服务器会检查。 -
它实际上是一个设备 MAC 地址,因为我正在从本地计算机运行客户端。我需要在 origin 中包含远程机器的 ip 吗?