how do I use the requests library to send data to an HTTP endpoint in MicroPython on an ESP8266?

Hello guys, how do I use the requests library to send data to an HTTP endpoint in MicroPython on an ESP8266? My code fails to connect. Here's the code:
import requests

response = request.post('http://example.com/data', json={'sensor': 'value'})
print(response.text)
import requests

response = request.post('http://example.com/data', json={'sensor': 'value'})
print(response.text)
@Middleware & OS
Solution:
Shouldn't that be
response = request.post('http://example.com/data', data={'sensor': 'value'})
response = request.post('http://example.com/data', data={'sensor': 'value'})
i.e. data instead of json...
Jump to solution
3 Replies
Solution
Ming
Ming9mo ago
Shouldn't that be
response = request.post('http://example.com/data', data={'sensor': 'value'})
response = request.post('http://example.com/data', data={'sensor': 'value'})
i.e. data instead of json
wafa_ath
wafa_ath9mo ago
MicroPython does not include the requests library. Instead, use urequests library
Enthernet Code
Enthernet Code9mo ago
Thanks, it worked 👍

Did you find this page helpful?