【发布时间】: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 -
我像你说的那样运行它,但同样的错误。