#๐Ÿ”’ OSError: stream operation not supported in `websocket` module in MicroPython

16 messages ยท Page 1 of 1 (latest)

quaint trout
#
# A simple example that:
# - Connects to a WiFi Network defined by "ssid" and "password"
# - Performs a GET request (loads a webpage)
# - Queries the current time from a server

import network   # handles connecting to WiFi
import urequests # handles making and servicing network requests
import websocket
import machine
import wifi_info
import server_info
import uasyncio

gp0 = machine.Pin(0, machine.Pin.OUT)
gp0.value(1)

# Connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# Fill in your network name (ssid) and password here:
wlan.connect(wifi_info.ssid, wifi_info.password)


# Example 1. Make a GET request for google.com and print HTML
# Print the html content from google.com
#print("1. Querying google.com:")
#r = urequests.get("http://www.google.com")
#print(r.content)
#r.close()

# Example 2. urequests can also handle basic json support! Let's get the current time from a server
#print("\n\n2. Querying the current GMT+0 time:")
#r = urequests.get("http://date.jsontest.com") # Server that returns the current GMT+0 time.
#print(r.json())

# WebSocket server address

# Create a WebSocket instance
ws = websocket.websocket(server_info.server_address)

# Connect to the WebSocket server
ws.connect(server_info.server_address)

# Send a message to the server
ws.send("Hello, WebSocket server!")

# Receive and print the response from the server
response = ws.recv()
print("Received response:", response)

# Close the WebSocket connection
ws.close()
upbeat tulipBOT
#

@quaint trout

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quaint trout
#

here is the error, I have no idea what's causing it but it appears to be the actual creation of the websocket instance

#

I'm new to python and I'm using MicroPython with Thonny so it's like impossible to find any information on what this error even means, everyone who had this error seems to just be using json manipulation functions

fickle talon
#

Are you sure that your micro-controller supports websockets at all?

quaint trout
#

as far as I've read it should

#

it's a Raspberry Pi Pico W

#

it has wifi connectivity so I feel like it should support web sockets

#

there is also a built-in library called websocket although I can't find any documentation on it in the MicroPython docs

#

I tried installing other websocket libraries but none of them were compatible with micropython

fickle talon
quaint trout
#

okay awesome I didn't know they had one, I'll try it out

quaint trout
upbeat tulipBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ OSError: stream operation not supported in websocket module in MicroPython