【问题标题】:autobahn.twisted.websocket opening handshake error 400autobahn.twisted.websocket 打开握手错误 400
【发布时间】:2018-02-07 17:10:45
【问题描述】:

问题:当 Bitfinex websocket API 连接建立应用程序出错时:

2018-02-07T18:51:52+0200 connecting once using transport type "websocket" over endpoint "tcp"
2018-02-07T18:51:52+0200 Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x106708550>
2018-02-07T18:51:52+0200 failing WebSocket opening handshake ('WebSocket connection upgrade failed (400 - BadRequest)')
2018-02-07T18:51:52+0200 dropping connection to peer tcp4:104.16.173.181:443 with abort=True: WebSocket connection upgrade failed (400 - BadRequest)
2018-02-07T18:51:52+0200 component failed: ConnectionAborted: Connection was aborted locally, using.
2018-02-07T18:51:52+0200 Connection failed: ConnectionAborted: Connection was aborted locally, using.
2018-02-07T18:51:52+0200 Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x106708550>

代码如下:

from autobahn.twisted.component import Component, run
import json

cmp_Bitfinex = Component(
    transports=[
        {
            u'type': u'websocket',
            u'url': u'wss://api.bitfinex.com/ws',
            u'endpoint': {
                u'type': u'tcp',
                u'host': 'api.bitfinex.com',
                u'port': 443,
            },
            u'options': {
                u"open_handshake_timeout": 100,
            }
        }
    ],
    realm=u"realm1",
)

@cmp_Bitfinex.on_join
def joined(self):
    def onTicker(*args):
        print("Ticker event received:", args)

    try:
        yield from self.subscribe(onTicker, 'ticker', options=json.dumps({
            "event": "subscribe",
            "channel": "ticker",
            "pair": "BTCUSD",
            "prec": "P0",
            "freq": "F0"
        }))

    except Exception as e:
        print("Could not subscribe to topic:", e)    

@cmp_Bitfinex.on_connect
def connected(session, details):
    print('Connected: {} \r\n {}'.format(session, details))

def main():
    run([cmp_Bitfinex])    

if __name__ == "__main__":
    main()

我了解,该问题可能出在应用程序发送的数据中。但是,我不明白我的代码到底出了什么问题。

应用使用python 3.6,最新的autobahn和最新的Twisted

【问题讨论】:

    标签: python-3.x api websocket twisted


    【解决方案1】:

    AFAICT 高速公路组件用于使用 WAMP 进行编程。 我认为您应该使用他们的websocket programmingCheck this example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-05
      • 2020-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      相关资源
      最近更新 更多