Python 错误 10042 Pusher WebSocket

Python error 10042 Pusher WebSocket

我尝试使用以下代码连接到 Pusher Websocket API: https://github.com/nlsdfnbch/Pysher/

import pysher

# Add a logging handler so we can see the raw communication data
import logging
root = logging.getLogger()
root.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
root.addHandler(ch)

pusher = pysher.Pusher('de504dc5763aeef9ff52')

# We can't subscribe until we've connected, so we use a callback handler
# to subscribe when able
def connect_handler(data):
    channel = pusher.subscribe('live_trades')
    channel.bind('trade', callback)

pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()

while True:
    # Do other things in the meantime here...
    time.sleep(1)

我每隔几秒就会得到这个,而不是一些有效的回应:

Connection: Error - [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call Connection: Connection closed Attempting to connect again in 10 seconds.

有什么问题?

我在使用 websockets 的不同库中看到了同样的错误。我可以从你的描述(和 link)中看出 Pysher 使用 websockets。

我发现 Python 的(又一个)websocket 客户端报告了 websockets 的问题,特别是 Python 3.6.4:[https://github.com/websocket-client/websocket-client/issues/370]

它也引用了 Python 跟踪器中的错误 [https://bugs.python.org/issue32394]

升级到 Python 3.6.5 对我有用。或者,他们建议升级到 Windows 10 1703+ 也应该有效(只是为了完整性;我还没有验证这一点)。