Can't connect to my Websocketserver

Hi everyone,
I’m trying to make a websocketserver in python on replit.

Here’s my code :

import asyncio
import websockets
import json 
import os

PORT = 8060

async def handler(websocket, path):
    print("New connection")
    data = await websocket.recv()
    parsedData = json.loads(data)

async def main():
    async with websockets.serve(handler,"",PORT):
        await asyncio.Future()  # garde le serveur ouvert indéfiniment

Normally, it should work because the preview starts (as soon as a port is open) and i get that message :

Failed to open a WebSocket connection: empty Connection header.
You cannot access a WebSocket server directly with a browser. You need a WebSocket >client.

I have tried to connect with these urls:

  • wss://
  • wss://
  • ws://
  • ws://

It’s not working …

Could someone help me ?
Thank you

Click Tools > Settings > Automatically open Webview when a port is open > disabled


How did you try connecting? You can’t go to them in your browser, you need to use JS or another python script,

1 Like

The issue is not about that

I tried in js with :

const client = new Websocket(link)

Did it not work? What errors did you get (JS side).
Can you also link your repl?

1 Like

I just had a sort of timeout message at the end of 30s a failure message.

Here’s the link :

Is your server running? Did you send any messages to the ws to test?

Did you try this URL with JS?

1 Like

hey there, could you post the js client you’re using

I think they are just using native WS lib.

oh I see, I popped some similar code in and connected via wss://url and it connected just fine, no stalling

Yeah I m using the native one


What’s the difference with the code ?


Nothing really… It was just a diff project with same base code

What is link? Try wss

I think the implication might be that they tried replacing link with all four links referenced in the original post?

1 Like

not sure whether it’s a typo, nor where you’re getting this error, but it’s WebSocket, not Websocket.

That link worked for 10min but it’s not anymore. It’s so random