0

It seems to be really hard to find anything about the WAMP.2 protocol. I am trying to connect to a webSocket that uses WAMP.2, using Python, autobahn and twisted. However, I keep getting this error:

2018-03-09 14:54:53+0100 [-] Log opened.
2018-03-09 14:54:53+0100 [-] Starting factory 
<autobahn.twisted.websocket.WebSocketClientFactory object at 0x000002A461F489B0>
2018-03-09 14:54:53+0100 [-] failing WebSocket opening handshake ('WebSocket connection upgrade failed (400 -ThisserveronlyspeaksWebSocketsubprotocolswamp.2.cbor.batched,wamp.2.cbor,wamp.2.msgpack.batched,wamp.2.msgpack,wamp.2.ubjson.batched,wamp.2.ubjson,wamp.2.json.batched,wamp.2.json)')
2018-03-09 14:54:53+0100 [-] dropping connection to peer tcp4:... with abort=True: WebSocket connection upgrade failed (400 - ThisserveronlyspeaksWebSocketsubprotocolswamp.2.cbor.batched,wamp.2.cbor,wamp.2.msgpack.batched,wamp.2.msgpack,wamp.2.ubjson.batched,wamp.2.ubjson,wamp.2.json.batched,wamp.2.json)
2018-03-09 14:54:53+0100 [-] Stopping factory 
<autobahn.twisted.websocket.WebSocketClientFactory object at 0x000002A461F489B0>
2018-03-09 14:55:01+0100 [-] Received SIGINT, shutting down.
2018-03-09 14:55:01+0100 [-] Main loop terminated.

Now, usually, when I get stuck I can find at least something about it on the internet. However, there seems to be little to no information about this (google doesn't even give any results relating WAMP.2).

I imagine that if webSocket servers are using WAMP.2 there must be a way to connect to them, right? If so, why is it so hard to find anything about it?

The code I am working with:

from autobahn.twisted.websocket import WebSocketClientFactory, 
WebSocketClientProtocol, connectWS
from twisted.internet import reactor

class EchoClientProtocol(WebSocketClientProtocol):

    def sendHello(self):
        self.sendMessage("Hello, world!")

    def onOpen(self):
        self.sendMessage("Hi there")

    def onMessage(self, msg, binary):
        print("Got echo: " + msg)
        reactor.callLater(1, self.sendHello)

if __name__ == '__main__':

    import sys

    from twisted.python import log

    log.startLogging(sys.stdout)
    factory = WebSocketClientFactory("wss://api.poloniex.com")
    factory.protocol = EchoClientProtocol
    connectWS(factory)
    reactor.run()
gre_gor
  • 6,669
  • 9
  • 47
  • 52
Lucas
  • 1
  • 1
  • 1
  • You will have to conform to the correct WAMP handshake; just any plain regular web socket connection won't cut it. Can't tell you off the top of my head what that is exactly though. – deceze Mar 09 '18 at 14:32

1 Answers1

0

WAMP is a protocol which sits on top of WebSocket, and you need a library which implements it.

Autobahn|Python does so, but you are trying to establish a pure WebSocket connection with a WAMP router. This will naturally fail.

For a basic example of how to connect to a WAMP router from Python, see e.g. https://github.com/crossbario/crossbar-examples/tree/master/hello/python

Side note: WAMP v2 is what all the implementations listed at http://wamp-proto.org/implementations/ are running. version 1 has pretty much been resigned to the history books.

gzost
  • 2,375
  • 1
  • 18
  • 25
  • Thanks for the short explanation! I was already afraid I was missing some information. I am gonna look into the example! – Lucas Mar 12 '18 at 15:14