vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 8
声望: 0

版主好!

连接币安时,有时ok,有时会出现:WebSocketProtocolException: Invalid close opcode.

完整信息:

[2020-11-17T17:20:42.496016]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
None
LastReceivedText:
None
Exception trace:

Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\Python\Anaconda3\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\Python\Anaconda3\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

关闭窗口后,出现:
Process finished with exit code -805306369 (0xCFFFFFFF)

Member
avatar
加入于:
帖子: 8
声望: 0

[2020-11-17T20:39:34.058442]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
None
LastReceivedText:
{"e": "listenKeyExpired", "E": 1605614404534}
Exception trace:
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\Python\Anaconda3\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\Python\Anaconda3\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\Python\Anaconda3\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

还有这种

Administrator
avatar
加入于:
帖子: 4749
声望: 278

请使用VN Studio试试,可能是你Anaconda中安装的websocket-client版本问题

Member
avatar
加入于:
帖子: 8
声望: 0

电脑中安装了vn studio,anaconda的websocket会自动升级么

Member
avatar
加入于:
帖子: 8
声望: 0

看了下,websocket-client是0.57.0最新版的

Administrator
avatar
加入于:
帖子: 4749
声望: 278

dengboren wrote:

电脑中安装了vn studio,anaconda的websocket会自动升级么

建议新手不要同时装两个Python,会互相污染模块加载路径的环境变量,只保留VNStudio试试吧

Member
avatar
加入于:
帖子: 8
声望: 0

确认了,我用的是conda环境运行vnpy,vnpy是git上下的master,conda的websocket-client是最新版0.57.0

Member
avatar
加入于:
帖子: 8
声望: 0

我看了下,问题会不会出在:VNPY的币安API没有发送Pong帧?

币安的Websocket文档:

Websocket 行情推送
...
每3分钟,服务端会发送ping帧,客户端应当在10分钟内回复pong帧,否则服务端会主动断开链接。允许客户端发送不成对的pong帧(即客户端可以以高于10分钟每次的频率发送pong帧保持链接)。

Member
avatar
加入于:
帖子: 8
声望: 0

我把anaconda卸载了,问题略微改变,但还是出问题:

除了开始两个错不一样,后面一直是invalid close opcode。这些都是vnstudio的环境包,vnpy是否存在问题呢?

[2020-11-22T13:50:13.128318]: Unhandled WebSocket Error:<class 'OSError'>
LastSentText:
None
LastReceivedText:
None
Exception trace:
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 249, in _run_ping
self._ping()
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 266, in _ping
ws.send("ping", websocket.ABNF.OPCODE_PING)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 253, in send
return self.send_frame(frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 279, in send_frame
l = self._send(data)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 449, in _send
return send(self.sock, data)
File "C:\vnstudio\lib\site-packages\websocket_socket.py", line 157, in send
return _send()
File "C:\vnstudio\lib\site-packages\websocket_socket.py", line 139, in _send
return sock.send(data)
File "C:\vnstudio\lib\ssl.py", line 984, in send
return self._sslobj.write(data)
OSError: [WinError 10014] 系统检测到在一个调用中尝试使用指针参数时的无效指针地址。
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 249, in _run_ping
self._ping()
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 266, in _ping
ws.send("ping", websocket.ABNF.OPCODE_PING)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 253, in send
return self.send_frame(frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 279, in send_frame
l = self._send(data)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 449, in _send
return send(self.sock, data)
File "C:\vnstudio\lib\site-packages\websocket_socket.py", line 157, in send
return _send()
File "C:\vnstudio\lib\site-packages\websocket_socket.py", line 139, in _send
return sock.send(data)
File "C:\vnstudio\lib\ssl.py", line 984, in send
return self._sslobj.write(data)
OSError: [WinError 10014] 系统检测到在一个调用中尝试使用指针参数时的无效指针地址。
[2020-11-22T13:50:21.099473]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
None
LastReceivedText:
None
Exception trace:
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
[2020-11-22T13:50:28.244849]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
None
LastReceivedText:
None
Exception trace:
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
[2020-11-22T13:50:30.478379]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
None
LastReceivedText:
None
Exception trace:
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
Traceback (most recent call last):
File "C:\vnpy\vnpy\api\websocket\websocket_client.py", line 200, in _run
text = ws.recv()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 314, in recv
opcode, data = self.recv_data()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 331, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 344, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 378, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

Administrator
avatar
加入于:
帖子: 4749
声望: 278

比较常见的可能性是网络问题,建议换个海外的AWS云服务器,另外一个可能就是交易所服务器异常重启,这种情况就没办法了

Member
avatar
加入于:
帖子: 8
声望: 0

好的,还是感谢了

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号