【问题标题】:Python error 10042 Pusher WebSocketPython 错误 10042 推送器 WebSocket
【发布时间】:2018-06-06 08:20:39
【问题描述】:

我尝试使用以下代码连接到 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)

我每隔几秒钟就会收到一次,而不是一些有效的响应:

连接:错误 - [WinError 10042] 未知、无效或 在 getsockopt 中指定了不受支持的选项或级别,或者 setsockopt 呼叫连接:连接已关闭尝试连接 10 秒后再次。

有什么问题?

【问题讨论】:

  • 你应该说一下'pysher'是什么以及从哪里得到它。我很确定不涉及 IDLE(并且应该删除它的标签)。要确定,请在命令行中直接使用 python 运行您的程序:python .../myprogram.py
  • 我像你说的那样运行它,但同样的错误。

标签: python pusher


【解决方案1】:

我在使用另一个使用 websockets 的库时看到了同样的错误。我可以从您的描述(和链接)中看到 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+ 也应该可以工作(只是为了完整性;我尚未验证这一点)。

【讨论】:

    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多