CoreS3 & HTTP Request block: urequests import error



  • Hi,

    I have started tinkering with the M5Stack and am finding it a very useful device. I can certainly see lots of potential.

    I wanted to test sending a POST HTTP request to a WLED device running on my network.

    I have tested the syntax outside of UiFlow 2.0 to be sure I have it correct.

    However, when I send the code to the device, I just get a blank screen.

    Also, when I tried sending it over the USB serial port, I encountered an error message...

    ImportError: no module named 'urequests'

    I have also tried a simple GET http request shown in the documentation and still got the same error.

    I am using v2.01 of UiFlow and have burned the latest to the device.

    A lot of searching didn't really get me to any simple solution.

    Any thoughts would be welcome.

    Many thanks in advance.



  • Update: Error message in image below.

    0_1707827727755_Screenshot 2024-02-13 at 02.51.42.png

    Whilst this got me bugged through the night, I have managed to get something working after REPL-ing into the CoreS3.

    The library urequests isn't there, but there is one called requests

    I have adapted my code to run in execute blocks in UiFlow to get a result. It's not the best, but it does work.

    Below is the same code but trying to use it in something else as part of my testing.
    0_1707827918343_Screenshot 2024-02-13 at 12.37.04.png

    Thanks again.



  • Might sound stupid but put the WLAN block after the http requests.
    Also you are missing the update block from the loop.



  • Same issue here. Also v2.0.1 on a Core2. Putting the WLAN block after the HTTP request also does not help.



  • I think the issue lies with the fact it’s importing urequests as request Try adding

    ‘’’ import urequests ‘’’



  • This results in:

    Traceback (most recent call last):
      File "<stdin>", line 5, in <module>
    ImportError: no module named 'urequests'
    >>> 
    


  • Well that's odd



  • Hi,

    I'm very new and just startet with M5Dial and UIFlow 2.0.1 yesterday.

    Adding http as Software and a HTTP request block results in this import line:
    import urequests as requests

    which leads to the error stated above:
    ImportError: no module named 'urequests'

    For me a fix ist to switch the code view to Custom Edit and rewrite this line as
    import requests

    or
    import requests as requests

    Now the code compiles and http requests are working.

    But for every change in the UI one have to reset the Custom Edit and enable it with this change again before doing another Run.

    Looking at this it seems that urequests have been renamed to requests 7 month ago. As far as I've read, UIFlow is based on MicroPython.

    They created a wrapper for urequests which would even help in our case:

    The MicroPython version of requests was previously called urequests and a lot of existing code depends on being able to still import the module by that name.
    This package provides a wrapper to allow this. Prefer to install and use the requests package instead.

    Any guess howto add a custom module in UIFlow 2.0 or tell the http block to import requests instead of urequests or update the used version of MIcropython?

    Kind regards



  • Add a execute block and type in the import request function



  • @streammyevent said in CoreS3 & HTTP Request block: urequests import error:

    This results in:

    Traceback (most recent call last):
      File "<stdin>", line 5, in <module>
    ImportError: no module named 'urequests'
    >>> 
    

    Sorry that should have been requests not urequests



  • @ajb2k3 said in CoreS3 & HTTP Request block: urequests import error:

    Add a execute block and type in the import request function

    I'm not sure if I get you right.
    I can add the custom import using a execute block.
    But this will add a new import line to the bottom of imports and the problematic import import urequests as requests will still exist in the code generated by UIFlow 2.1. Therefore the error persists.

    Here is a screenshot of what I'm talking about:

    0_1708603172623_50818acb-4ed1-4ebc-b71a-f2e44a7c30cf-image.png

    It's weird anyway, as the Web console states, that MicroPython 1.22 is running, which should contain the Wrapper package urequests anyway.



  • This was my original question really.

    If I add any HTTP block into UiFlow2.x then it will include import urequests in the code.

    This will fail, even if I add an import requests myself.

    So my solution was to use a code block instead of a http block to perform the task I wanted, but a little on the clumsy side and not really what UiFlow was meant to be used.

    I wonder if I imported reuqests as urequests and then urequests as request it would fool it?

    Tim



  • @_andreas_ said in CoreS3 & HTTP Request block: urequests import error:

    @ajb2k3 said in CoreS3 & HTTP Request block: urequests import error:

    Add a execute block and type in the import request function

    I'm not sure if I get you right.
    I can add the custom import using a execute block.
    But this will add a new import line to the bottom of imports and the problematic import import urequests as requests will still exist in the code generated by UIFlow 2.1. Therefore the error persists.

    Here is a screenshot of what I'm talking about:

    0_1708603172623_50818acb-4ed1-4ebc-b71a-f2e44a7c30cf-image.png

    It's weird anyway, as the Web console states, that MicroPython 1.22 is running, which should contain the Wrapper package urequests anyway.

    Sort of but you are actually importing my the library Twice but with different names. Which in theory will sometimes fix the issue if it can’t find a library with one of the names.

    It’s a bridge fix if one of the libraries is spelt wrong in the import as we have here



  • urequests is not a typo, the u stands for μ, the Greek symbol for micro. Meaning: "micro"-requests, a smaller version of the requests library, slimmed down for micropython.
    I have read that urequests has also now been replaced by urllib.request as a further optimised version for low memory ESP devices.

    I believe the included "requests" library may be too large for the memory of the S3, and urequests IS the intended library that should be included in the firmware (which it is not)

    Using requests instead of urequests in my code I get the following error:
    File "requests/init.py", line 180, in get
    File "requests/init.py", line 93, in request
    OSError: [Errno 12] ENOMEM