2

We have a Node.js process spitting out data we need to consume. It's already being consumed by a JS front-end, but we need another application to consume the data as well to do some data analysis. We decided to write it in Python. One limitation is we can only use Python 2.

We found a Python websocket library, websocket-client. It comes with a sample, and we even saw it in another question here on StackOverflow.

The problem is, we can't even get any of the samples to work, much less what we really need to do.

This sample crashes on line 4, when it tries to connect, create_connection():

#!/usr/bin/python

from websocket import create_connection
ws = create_connection("ws://localhost:8080/websocket")

print( "Sending 'Hello, World'..." )
ws.send("Hello, World")
print( "Sent" )
print( "Reeiving..." )
result =  ws.recv()
print( "Received '%s'" % result )
ws.close()

It gives this error:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Clearly our local machines are refusing connections, but this even simpler sample crashes as well:

import websocket

ws = websocket.WebSocket()
ws.connect("ws://example.com/websocket", http_proxy_host="proxy_host_name", http_proxy_port=3128)

It fails on the connect line with this error:

websocket._exceptions.WebSocketAddressException: [Errno 11004] getaddrinfo failed

What can we do to get even simple samples to work? We know nearly nothing about websockets, so please forgive our ignorance.

Frecklefoot
  • 1,554
  • 1
  • 15
  • 43

0 Answers0