Skip to content

"no module named 'usocket'" on Raspberry Pico W #35

Open
@noinskit

Description

@noinskit

Hi,

I'm trying to use this package in order to run an HTTP Server (Microdot) concurrently with other tasks on Raspberry Pico W.
It's failing for me with:

Traceback (most recent call last):
  File "<stdin>", line 42, in <module>
  File "microdot_asyncio.py", line 320, in run
  File "asyncio/core.py", line 297, in run
  File "asyncio/core.py", line 261, in run_until_complete
  File "asyncio/core.py", line 246, in run_until_complete
  File "microdot_asyncio.py", line 278, in start_server
  File "asyncio/stream.py", line 226, in start_server
ImportError: no module named 'usocket'

Am I doing something totally unsupported yet, like maybe only some subset of CircuitPython devices have usocket?

I know that sockets generally work if I use socketpool for screating sockets, so maybe I'm really looking after #4 ?

I'd appreciate any pointers!

Activity

dhalbert

dhalbert commented on Nov 20, 2022

@dhalbert
Contributor

CircuitPython doesn't have usocket, but you can use socketpool. It looks like the microdot server is written for MicroPython, not CircuitPython, but you could modify it.

noinskit

noinskit commented on Nov 20, 2022

@noinskit
Author

I believe that usocket is called from within Adafruit_CircuitPython_asyncio directly.

From what I can see microdot server is only using asyncio and its start_server method, which doesn't sound like depending on MicroPython.

This is my attempt at minimal repro without using Microdot:

import asyncio

async def main():
    async def serve(reader, writer):
        pass
    
    await asyncio.start_server(serve, "0.0.0.0", 80)

asyncio.run(main())

Note that I'm not really initializing wifi in my example, but since I would not be able to pass the initialized socket pool to asyncio anyway, it wouldn't help.

The result:

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "asyncio/core.py", line 297, in run
  File "asyncio/core.py", line 261, in run_until_complete
  File "asyncio/core.py", line 246, in run_until_complete
  File "<stdin>", line 7, in main
  File "asyncio/stream.py", line 226, in start_server
ImportError: no module named 'usocket'

I'll admit that in the meantime I also tried to make a socketpool.SocketPool object pretend to be the usocket module for the sake of asyncio, but it's currently failing for me onsocket objects from there not having a setsockopt method.

dhalbert

dhalbert commented on Nov 20, 2022

@dhalbert
Contributor

You're right, we should change this line:

import usocket as socket

noinskit

noinskit commented on Nov 20, 2022

@noinskit
Author

Also true, but in my case I think it's about the server part:

import usocket as socket

chrismurf

chrismurf commented on Nov 29, 2022

@chrismurf

This bit me tonight with the AdaFruit ESP32 Feather V2 as well, so for anybody new and googling - it's not specific to the Raspberry Pico W at all.

I believe this will also affect open_connection calls.

jordonsc

jordonsc commented on Sep 25, 2023

@jordonsc

The same applies to the uerrno import on the line above.

byzantic

byzantic commented on Jan 30, 2024

@byzantic

I'm having the same issue here, except that I am trying to use the Wiznet W5500-EVB-Pico.

Now, interestingly, this does have a socket implementation already (adafruit_wiznet5k.adafruit_wiznet5k_socket) .. but how would I set up asyncio to use that instead?

mcarlson

mcarlson commented on Feb 29, 2024

@mcarlson

This bit me also, which is too bad because the official circuitpython story for not supporing interrupts/multithreading (which I get!) is to use asyncio for applications where you need to do more than one thing at a time. For me, that means going back to micropython as I'm building 'headless' apps that rely on microdot/being able to run an async server.

Not super stoked because the story for not having interrupts in circuitpython is is 'use asyncio' per https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio/overview

But, the circuitpython asyncio doesn't work with microdot because they don't implement start_server. So I'm blocked... Please fix this!

sjev

sjev commented on May 8, 2024

@sjev

.... this issue is still relevant and affects probably all ports. I was making a switch from Micropython to Circuitpython, but tripped on:

asyncio.create_task(asyncio.start_server(serve_client, "0.0.0.0", 80))

crashes with

Traceback (most recent call last):
  File "asyncio/core.py", line 261, in run_until_complete
  File "asyncio/stream.py", line 225, in start_server
ImportError: no module named 'usocket'

Major bummer 😞 , given that according to docs start_server should be supported. Shouldn't this be in test coverage?

mcarlson

mcarlson commented on May 8, 2024

@mcarlson
mattytrentini

mattytrentini commented on May 9, 2024

@mattytrentini

I believe it really should be fixed. For me, I wasn’t able to continue with micropython because of it.

Just to clarify @mcarlson, I think you mean CircuitPython here? I've been using microdot on MicroPython for years with no issue whatsoever...

dhalbert

dhalbert commented on May 9, 2024

@dhalbert
Contributor

Have any of you tried the source version and just fixed the import names? I started a PR to do that. There are only a few lines to change. It might still be the case that something doesn't work.

mcarlson

mcarlson commented on May 9, 2024

@mcarlson

19 remaining items

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      "no module named 'usocket'" on Raspberry Pico W · Issue #35 · adafruit/Adafruit_CircuitPython_asyncio