Python Forum

Full Version: Can't connect to websocket
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I've spent some time now trying to connect to this websocket and I tried at least five different socket libraries trying to connect with no joy.  Think I'm using Python 3.6

Depending on the library I ended up with either this:

This code:

import websocket

def on_message(ws, message):
   print("Message: " + message)

def on_error(ws, error):
   print("Error: " + error)

def on_close(ws, close):

if __name__ == "__main__":

   ws = websocket.WebSocketApp("wss://",

   result = ws.recv()
   print("Received '%s'" % result)

File "C:\Program Files\Python36\lib\site-packages\websocket\", line 120, in send    "Connection is already closed.") websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
While this:

import asyncio
import websockets

async def hello():
   async with websockets.connect('wss://') as websocket:
       name = input("[0~Poloniex~BTC~USD]")
       await websocket.send(name)
       print("> {}".format(name))

       greeting = await websocket.recv()
       print("< {}".format(greeting))

Came up with this error:

File "C:\Program Files\Python36\lib\site-packages\websockets\", line 81, in handshake raise InvalidHandshake("Malformed HTTP message") from exc websockets.exceptions.InvalidHandshake: Malformed HTTP message
In the case of the second error I tried changing the format of the message, converting it to json, removing square brackets, etc. without success.

Is there someone who could give me some guidance on connecting to the websocket please?

Server side runs the socket on

Any help is greatly appreciated!

Thank you all!
I found a solution to my problem. The websocket in question is no longer online. Big Grin
Hi Iaas

Could you please let me know how you found that wss:// is no longer online? The crypto compare website docs still seem to refer to this.