I have wrote this code for raspberry pi pico W
using those libraries:
import rp2
import network
import ubinascii
import machine
import urequests as requests
import time
import socket
The code :
headers = {"content-type: application/json"}
payload = {"DeviceID": 1,
"temp":1,
"humidity":0,
"data1":0}
print(payload)
print("Executing POST")
response = requests.post(url2, headers=headers, data=payload)
print("sent (" + str(response.status_code) + "), status = " + str(wlan.status()) )
print("POST execution succes")
response.close()
I successfully made a get request.
And I got lots of errors trying POST in Thonny compiler. I have tried to change a lot of things and this is the final form that doesn’t work :).
>Solution :
Okay so you pointed out the error was:
TypeError: 'set' object isn't subscriptable
When looking to see where you defined a set, I saw this set definition:
headers = {"content-type: application/json"}
You surely meant to define it as a dictionary – you’re missing a couple of quotes:
headers = {"content-type": "application/json"}
Both sets and dicts are defined via curly braces; you were defining a set because you weren’t using dict notation, which requires the : to not be contained within a string, like you had.