[Errno 32] Broken pipe

I am streaming quotes through websockets using the following endpoint and the python websockets module

Endpoint: “wss://stream.data.alpaca.markets/v2/sip”

I receive data for a few minutes until my code crashes with the error: [Errno 32] Broken pipe

I am not very experienced or knowledgable with internet protocols/websocket so I was hoping someone could point me in the right direction. I am wondering if this could be a server side issue. Anyone else experience this?

Here’s the traceback:

— request header —
GET /v2/sip HTTP/1.1
Upgrade: websocket
Host: stream.data.alpaca.markets
Origin: http://stream.data.alpaca.markets
Sec-WebSocket-Key: Bxv4fwZ2OR+apkATTG23rQ==
Sec-WebSocket-Version: 13
Connection: Upgrade

— response header —
HTTP/1.1 101 Switching Protocols
Date: Fri, 18 Mar 2022 14:51:41 GMT
Connection: upgrade
Sec-Websocket-Accept: 4uLNiabuMgALJv6y09RjUxkbVec=
Upgrade: websocket
Strict-Transport-Security: max-age=15724800; includeSubDomains

Suggest running the same code on some sort of cloud server, e.g. I use www.iDriveCompute.com with a New York data center. Nothing special about this provider, any cloud provider with the right specs will be more reliable compared to a home PC with a retail internet connection.

If running this code at home, how do you connect to the internet? Wired or wireless? A wired connection always beats a WiFi connection in terms of stability.

There are other solutions too: if you do get a broken pipe (due to a transient drop in the internet connection) you can detect this, reconnect and resume the connection.