2

I am using a micropython firmware version esp8266-20190125-v1.10.bin for esp8266mod. I accessed REPL prompt via a wired connection using picocom and connected the device to my home wifi. I was trying to send some HTTP post requests using urequests.

import urequests response = urequests.post('http://lakshmick.pythonanywhere.com/savedata', data = {'string': 'posting from micropython'})

I got some error like this:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "urequests.py", line 115, in post
    File "urequests.py", line 100, in request
    File "urequests.py", line 79, in request
TypeError: object with buffer protocol required

Does it require any additional configuration procedures before importing urequests?

1 Answer 1

5

You need to serialize the data into a string before sending it:

myPostedData = {'YYYY' : 100}
res = urequest.post('https://XXX.amazonaws.com/XXX/XXX', data=json.dumps(myPostedData))
jsonresults = json.loads(res.content)
Sign up to request clarification or add additional context in comments.

2 Comments

@nekomatic No, data=json.dumps(myPostedData) json.dumps does what @Phil states, serialize's the data.
@wildernessfamily it looks like I posted the comment first and then edited the answer, which made my comment obsolete (see the edit history). Thanks for pointing out the potential confusion! I've deleted the original comment now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.