urequests "need more than 2 values to unpack"

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
techykermit
Posts: 5
Joined: Tue Dec 31, 2019 5:42 pm

urequests "need more than 2 values to unpack"

Post by techykermit » Tue Dec 31, 2019 5:47 pm

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:

Code: Select all

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:

Code: Select all

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: urequests "need more than 2 values to unpack"

Post by pythoncoder » Wed Jan 01, 2020 5:49 am

Pycom have their own firmware so it might be worth raising the question on their forum.
Peter Hinch
Index to my micropython libraries.

techykermit
Posts: 5
Joined: Tue Dec 31, 2019 5:42 pm

Re: urequests "need more than 2 values to unpack"

Post by techykermit » Wed Jan 01, 2020 3:54 pm

Yes, correct. However, I downloaded the library from micropython-lib, so I thought I could get help here...
But if the Pycom forum is better, I will move there. Thanks!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: urequests "need more than 2 values to unpack"

Post by pythoncoder » Thu Jan 02, 2020 2:55 pm

From a quick look at the urequests code, your url should be of the form http://google.com or http://abc/def/xyz. Also data should be a bytes or bytearray type for sending to a socket.

However I don't know if there are Pycom issues: they have their own firmware and seem to maintain their own library, so I don't know how compatible the official MicroPython library might be.
Peter Hinch
Index to my micropython libraries.

techykermit
Posts: 5
Joined: Tue Dec 31, 2019 5:42 pm

Re: urequests "need more than 2 values to unpack"

Post by techykermit » Thu Jan 02, 2020 6:44 pm

I posted this over at the Pycom forum, and it was one of these silly issues you can make when programming that turn out to be really simple when somebody else answers it... I simply forgot http:// in front of the URL.

DanielNduati
Posts: 2
Joined: Sun Jan 31, 2021 6:25 pm

Re: urequests "need more than 2 values to unpack"

Post by DanielNduati » Tue Mar 02, 2021 7:14 pm

Hello
I am also sending data to a server via HTTP post requests on the esp 32 but get the same error :

Code: Select all

Traceback (most recent call last):
  File "main.py", line 34, in <module>
  File "urequests.py", line 111, in post
  File "urequests.py", line 81, in request
ValueError: need more than 2 values to unpack
I've tried the fix above but it doesn't work for me here's my url:

Code: Select all

dataUrl = "https://XXXXXXXX/api/data"

heres line 34:

Code: Select all

publishResponse =requests.post(dataUrl,data=publishData,headers=publishHeaders)
And here are the headers and data
publish header:

Code: Select all

publishHeaders = {"content-type":'application/json',"Authorization":' Bearer '+str(accessToken)+''}
publishData:

Code: Select all

publishData='[{"sourceId":"XXXXXXXXX","values":[{"ts":"2021-03-02T22:37:00Z","value":69}]}]'

DanielNduati
Posts: 2
Joined: Sun Jan 31, 2021 6:25 pm

Re: urequests "need more than 2 values to unpack"

Post by DanielNduati » Thu Mar 25, 2021 6:02 am

Apparently the post request does reflect on the server but still id really like to get rid of the error please anyone....

ldmoretti
Posts: 5
Joined: Fri Mar 26, 2021 1:34 am

Re: urequests "need more than 2 values to unpack"

Post by ldmoretti » Fri Mar 26, 2021 1:59 am

Daniel:
Have you tried just "http" not "https" in your URL? Might be an issue of the stack not supporting secure transfer.

Post Reply