我的Python脚本创建了一个WebSocket,并且能够使用该WebSocket连接到服务器。服务器在我创建的WebSocket上发送响应,但WebSocket模块似乎无法对其进行解码。
这是我看到的错误:
-----------------------
Traceback (most recent call last):
File "test_file.py", line 307, in <module>
result = ws.recv()
File "/usr/local/lib/python2.7/dist-packages/websocket/_core.py", line 293, in recv
opcode, data = self.recv_data()
File "/usr/local/lib/python2.7/dist-packages/websocket/_core.py", line 310, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/usr/local/lib/python2.7/dist-packages/websocket/_core.py", line 334, in recv_data_frame
return self.cont_frame.extract(frame)
File "/usr/local/lib/python2.7/dist-packages/websocket/_abnf.py", line 428, in extract
"cannot decode: " + repr(frame.data))
websocket._exceptions.WebSocketPayloadException: cannot decode: '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x9dUmk\xeb6\x14\xfe+\xc1\x1f\xc7ug\'v\x1c\x17\xc6\xb8t\xa5\x0b\xac\xbdwm\x06\x83\xb9\x08Y>N\xb5kK\x8e$\'\xcdJ\xff\xfbt$;vac0\x87\x18\xe9\xbc<\xe7\xfd\xf8m\x11\x80RR1YAp\xbd\x88>-\x82\x16\xb4\xa6{\xbc\x05\x9f\xf7 \xccW%_\xcf7\xb2m{\xc1\x195\\\x8a\xc0JqMz\'
这是我在启动websocket并收听服务器resopnse的代码:
ws = websocket.create_connection(full_url, header = header_set)
result = ws.recv()
print result
它在ws.recv()
行失败了。有什么想法吗?
答案 0 :(得分:0)
这似乎是let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
let bigAttr = [NSForegroundColorAttributeName: UIColor.white,
NSFontAttributeName: UIFont.systemFont(ofSize: 60, weight: UIFontWeightLight),
NSParagraphStyleAttributeName: paragraphStyle]
let smallAttr = [NSFontAttributeName: UIFont.systemFont(ofSize: 12, weight: UIFontWeightLight)]
let attributedString = NSMutableAttributedString(string: "\(speedInt)", attributes: bigAttr)
attributedString.append(NSAttributedString(string: "\nkm/h", attributes: smallAttr))
statusLabel.attributedText = attributedString
版本websocket-client
的已知问题。尝试将软件包更新到0.16
或更高版本,看看是否能解决问题。
显然,这是因为0.34
改变了他们在websocket-client
之后的版本中处理帧验证的方式(不完全确定版本是什么,所以请尝试更新到最新版本。)
支持链接: https://github.com/dpallot/simple-websocket-server/issues/24