Websocket redirected to https:// scheme instead of wss:// for Python backend

I have a Python backend deployed to Render. It is built with FastAPI. I recently tried to add a websocket endpoint to the server. I got it working locally, but when I deployed to Render, I couldn’t connect to the endpoint.

Originally, the client was simply connecting via an unencrypted ws:// connection. Makes sense that render wouldn’t like that. But the response was weird. Render responds to that connection with a redirect telling the client to connect to the same path but using https://. I would have expected that the connection would be redirected to the encrypted websocket scheme wss://, not https://.

Is this redirect an issue on Render’s side? My server logs never indicate that they even received a connection when using the ws:// scheme. And when I manually set wss://, I strangely receive a 404.

I’m wondering if there isn’t some particular network settings stuff going on with the Python deployment. Will try deploying my service with Docker instead of Render’s native Python deployment and see how that goes. Seems like other comments have indicated that might be helpful.

Sigh. User error. Shipped without installing the websockets library thus the connection couldn’t be established. When updating requirements.txt and connecting on the client with wss:// it worked.

Glad that’s over :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.