Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4997

Python • Re: Websockets = :-(

$
0
0
I have websockets installed on my raspberry pi but I am unable to establish a connection.

pip show websocket-client

Code:

pi@popcamera:~ $ pip show websocket-clientName: websocket-clientVersion: 1.2.3Summary: WebSocket client for Python with low level API optionsHome-page: https://github.com/websocket-client/websocket-client.gitAuthor: lirisAuthor-email: liris.pp@gmail.comLicense: Apache-2.0Location: /usr/lib/python3/dist-packagesRequires: Required-by: 
The following python code yields errors:

Code:

import websocketimport base64# WebSocket setupws_url = "ws://localhost:7071"  # Adjust the WebSocket server URL if neededws = websocket.create_connection(ws_url)
What errors do you see?

Have you googled the error messages to find a cause and perhaps a solution?
Actually, I just tried this code and it just worked. Websocket connected!

Code:

import websocketws_url = "ws://localhost:7071"try:    ws = websocket.create_connection(ws_url)    print("WebSocket connection established")except Exception as e:    print("Failed to connect to WebSocket:", e)    sys.exit(1)

Statistics: Posted by MRV — Thu Nov 07, 2024 3:59 pm



Viewing all articles
Browse latest Browse all 4997

Trending Articles