I'm trying to connect to a WAMP websocket server using Python and subscribe to receive messages, but I'm not able to achieve it. I have managed to connect using Autobahn on JS with this code:
< script src = "autobahn.js" > < /script> <script >
var conn = new ab.Session('ws://examplehost.com:8443/ws',
function() {
conn.subscribe('channel', function(topic, data) {
console.log(data);
alert('New data arrived: "' + topic + '" : ' + data.title);});},
function() {
console.warn('WebSocket connection closed');
}, {'skipSubprotocolCheck': true});
</script>
But using the same library on Python with below code results on 404 error:
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
class Component(ApplicationSession):
async def onJoin(self, details):
def on_event(i):
print("New data arrived: {}".format(i))
await self.subscribe(on_event, 'channel')
if __name__ == '__main__':
url = "ws://examplehost.com:8443/ws"
runner = ApplicationRunner(url)
runner.run(Component)
And this is the error I get:
failing WebSocket opening handshake ('WebSocket connection upgrade failed (404 - NotFound)')
dropping connection to peer tcp4:123.123.123.123:8443 with abort=True: WebSocket connection upgrade failed (404 - NotFound)
Any idea on how to solve this? After searching a lot maybe using the path /ws
on the server is causing some issues, but I'm not sure. I have also tried with many other Python modules, but not luck.