🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    CoreS3 & HTTP Request block: urequests import error

    UiFlow 2.0
    5
    17
    4.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MadeFLM
      MadeFL
      last edited by

      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.

      1 Reply Last reply Reply Quote 1
      • MadeFLM
        MadeFL
        last edited by MadeFL

        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.

        1 Reply Last reply Reply Quote 1
        • ajb2k3A
          ajb2k3
          last edited by ajb2k3

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

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          1 Reply Last reply Reply Quote 0
          • S
            streammyevent
            last edited by

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

            1 Reply Last reply Reply Quote 1
            • ajb2k3A
              ajb2k3
              last edited by

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

              ‘’’ import urequests ‘’’

              UIFlow, so easy an adult can learn it!
              If I don't know it, be patient!
              I've ether not learned it or am too drunk to remember it!
              Author of the WIP UIFlow Handbook!
              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

              1 Reply Last reply Reply Quote 0
              • S
                streammyevent
                last edited by

                This results in:

                Traceback (most recent call last):
                  File "<stdin>", line 5, in <module>
                ImportError: no module named 'urequests'
                >>> 
                
                ajb2k3A 1 Reply Last reply Reply Quote 1
                • ajb2k3A
                  ajb2k3
                  last edited by

                  Well that's odd

                  UIFlow, so easy an adult can learn it!
                  If I don't know it, be patient!
                  I've ether not learned it or am too drunk to remember it!
                  Author of the WIP UIFlow Handbook!
                  M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                  1 Reply Last reply Reply Quote 0
                  • _
                    _andreas_
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 1
                    • ajb2k3A
                      ajb2k3
                      last edited by

                      Add a execute block and type in the import request function

                      UIFlow, so easy an adult can learn it!
                      If I don't know it, be patient!
                      I've ether not learned it or am too drunk to remember it!
                      Author of the WIP UIFlow Handbook!
                      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                      1 Reply Last reply Reply Quote 0
                      • ajb2k3A
                        ajb2k3 @streammyevent
                        last edited by

                        @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

                        UIFlow, so easy an adult can learn it!
                        If I don't know it, be patient!
                        I've ether not learned it or am too drunk to remember it!
                        Author of the WIP UIFlow Handbook!
                        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                        1 Reply Last reply Reply Quote 0
                        • _
                          _andreas_
                          last edited by

                          @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.

                          ajb2k3A 1 Reply Last reply Reply Quote 0
                          • MadeFLM
                            MadeFL
                            last edited by

                            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

                            1 Reply Last reply Reply Quote 0
                            • ajb2k3A
                              ajb2k3 @_andreas_
                              last edited by

                              @_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

                              UIFlow, so easy an adult can learn it!
                              If I don't know it, be patient!
                              I've ether not learned it or am too drunk to remember it!
                              Author of the WIP UIFlow Handbook!
                              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                              1 Reply Last reply Reply Quote 0
                              • M
                                mikeluyten
                                last edited by

                                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

                                1 Reply Last reply Reply Quote 1
                                • _
                                  _andreas_
                                  last edited by

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

                                  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)

                                  this is imho not the point of this topic. The problem is, that using the http block in UIFlow 2.0.1 leads to an invalid import. The block must be adopted to either import requests instead of urequests or someone has to check, why the urequests wrapper package from Micropython cannot be loaded (which should load requests due to the renaming in Micropython 7 month ago).

                                  Until than, http block is not usable without editing the code afterwards (which leads to the fact, that one cannot longer use the UI for programming).

                                  For now I've solved it by replacing all http blocks with Execute my python blocks containing these two lines:

                                  http_req = requests.get('http://my.local/url', headers={})
                                  http_req.close()
                                  

                                  Since I do not need the response this is even shorter than using the http block.

                                  1 Reply Last reply Reply Quote 2
                                  • _
                                    _andreas_
                                    last edited by

                                    Hi,

                                    FYI: I've got a response from m5stack support regarding this issue:

                                    Below issue is caused by the mpy version changing. We may fix it by next version, which should be next Friday. Thx!

                                    M 1 Reply Last reply Reply Quote 3
                                    • M
                                      mikeluyten @_andreas_
                                      last edited by

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

                                      Hi,

                                      FYI: I've got a response from m5stack support regarding this issue:

                                      Below issue is caused by the mpy version changing. We may fix it by next version, which should be next Friday. Thx!

                                      Can confirm, this is now fixed!

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post