Skip to content

Problems on raspberry pi pico W #2

Description

@edmcman

Hi,

I'm trying to use uAPI on a raspberry pi pico W. Here's my script:

import uasyncio
import network
from time import sleep
from uAPI import uAPI, HTTPResponse

wlan = network.WLAN(network.STA_IF)
while wlan.isconnected() == False:
    print('Waiting for connection...')
    sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')

api = uAPI(
    port=80,
    title="Hello uAPI!",
    description="My First API with uAPI.",
    version="1.0.0",
)

@api.endpoint("/test", "GET")
def hello_world():
    print("Console: Hello World!")
    return HTTPResponse(data="Response: Hello World!", content_type="text/plain")


try:
    uasyncio.run(api.run())
except KeyboardInterrupt:
    print("Stopping")
    api.stop()
except Exception as e:
    print("Error:", e)
    api.stop()

When I try to test the API, I get a 500 response:

ed@penguin ~/u/docs (main) [8]> wget 192.168.1.83/test
--2024-12-08 10:12:30--  http://192.168.1.83/test
Connecting to 192.168.1.83:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2024-12-08 10:12:30 ERROR 500: Internal Server Error.

On the console, I see:

Got a connection from ('192.168.1.36', 36392)
[Errno 11] EAGAIN

It seems like maybe reading the socket in nonblocking mode is the problem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions