Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    urequests "need more than 2 values to unpack"

    Scheduled Pinned Locked Moved WiPy 2&3
    8 Posts 3 Posters 304 Views 3 Watching
    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.
    • techykermitT Offline
      techykermit
      last edited by

      I thought I should post this on the MicroPython forum (as I am using urequests from the micropython-lib), but I was directed to post here. So I guess I'll do that.

      Here is my problem:
      Hi!
      I am trying to send a request to my OTA update server using urequests.
      However, I am getting an exception that I found somewhat strange:

      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "ota.py", line 50, in <module>
        File "ota.py", line 50, in <module>
        File "ota.py", line 47, in <module>
        File "/flash/lib/urequests.py", line 114, in get
        File "/flash/lib/urequests.py", line 39, in request
      ValueError: need more than 2 values to unpack
      

      The request code I am using is:

      urequests.get(url, headers={"User-Agent": "xxx (not actual value)"}, data={"deviceid": "xxx (not actual value)"})
      

      Can someone figure this out for me? If I remove one of these, I still get the exception, but with "need more than 1 value to unpack".
      The board I am using is a PyCom WiPy 3.0.

      robert-hhR 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @techykermit
        last edited by

        @techykermit Can you tell, which of the various urequest variants you are trying?

        techykermitT 1 Reply Last reply Reply Quote 0
        • techykermitT Offline
          techykermit @robert-hh
          last edited by

          @robert-hh This is the urequests I am using (from micropython-lib):
          https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py

          1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @techykermit
            last edited by

            @techykermit So line 39 is:
            proto, dummy, host = url.split("/", 2)
            What is the content of url? It should be of the form:
            'proto://host' e.g.
            'https://forum.pycom.io'

            J techykermitT 2 Replies Last reply Reply Quote 0
            • J Offline
              jcaron @robert-hh
              last edited by

              @robert-hh Line numbers don’t match. Line 114 is not in get, so it’s unlikely line 39 matches (and the error message definitely doesn’t match).

              @techykermit can you double check what version of urequests you are using?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @jcaron
                last edited by robert-hh

                @jcaron I do not agree, especially since I verified that: to my surprise the error message matches. if you use a string like:
                url = http:/x.y
                line 39 will produce exactly this error message. You can try yourself in REPL:

                proto, dummy, host = "x:/y.z".split("/", 2)

                I looked first for something like struct.unpack() as the source of the error. And so I learned that split may cause that message too.

                1 Reply Last reply Reply Quote 1
                • techykermitT Offline
                  techykermit @robert-hh
                  last edited by

                  @robert-hh This is another one of those silly mistakes you make while coding... I loaded the URL from a data storage file but forgot to add https:// in the beginning. It works fine now!

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @techykermit
                    last edited by

                    @techykermit Things like these happen all of us the time. But still, the python code could have an error handling for it, like the two lines before.

                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom