urequests with post - buffer protocol required

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ryanjennings
Posts: 4
Joined: Tue Aug 30, 2016 12:29 pm

urequests with post - buffer protocol required

Post by ryanjennings » Tue Sep 27, 2016 10:02 pm

I am trying to do a post with urequests. I am running into a TypeError.

Code: Select all

>>> r = urequests.post("http://www.xxxxxxxxxxxxxx.com:8086", data = {'basement' : 60.2, 'outside': 80.4})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "urequests.py", line 104, in post
  File "urequests.py", line 74, in request
TypeError: object with buffer protocol required
please use the code blocks - platforma
Any suggestions on what I might try?

Thanks for the help,
Ryan

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: urequests with post - buffer protocol required

Post by kfricke » Tue Sep 27, 2016 10:11 pm

Without explicitly knowing the exact interface, i do recall that the method does expect a string or bytearray as the type of data argument. You are passing a dictionary directly, which throws that TypeError.

For conversion into an string you can use the JSON module or craft the simple JSON string by hand and in-place.

ryanjennings
Posts: 4
Joined: Tue Aug 30, 2016 12:29 pm

Re: urequests with post - buffer protocol required

Post by ryanjennings » Tue Oct 11, 2016 4:15 am

Thanks for the help things are working better now.

Post Reply