I am working with Pi Pico W, it is already connected to the Wi-Fi, I can see it in the ifconfig() output.
Furthermore, I am using this urequests code from https://github.com/micropython/micropython-lib/blob/master/python-ecosys/urequests/urequests.py. When I tried to update the records, I received the following error:
This one Going 0113A70CA811 {'27/02/2023': {'clock': '09:26', 'anamolies': 'Lateness', 'machine': 'IT'}}
Unhandled exception in thread started by <function send_data at 0x2000d000>
Traceback (most recent call last):
File "<stdin>", line 104, in send_data
File "request.py", line 10, in put_request
File "urequests.py", line 188, in put
File "urequests.py", line 76, in request
ValueError: Unsupported protocol: mongodb+srv:
I tried to check the Api server/URL from Postman but its working fine, I extended timeout in request by 10 sec, I even rebooted pi. Nothing helped.
I don't know what's the cause!
Update
So basically I am using almost the same setup and code as https://github.com/sbcshop/Raspberry-Pi-Pico-RFID-Expansion this project. Just I am using RPi Pico W for connection. More, running two threades in main.py, first will read and display the tag, second one will send request. Also I have update extact url below.
One more think to mention, earlier with the same modules and URL I was able to request, was working fine.
request.py
import urequests
import json
import MSAL
def put_request(id, json_data):
url = 'https://url/app/clock/{}'.format(id)
headers = {'Content-Type': 'application/json', 'Authorization': '{}'.format(MSAL.get_token())}
response = urequests.put(url, data=json.dumps(json_data), headers=headers)
print(response.text)
response.close()
main.py
def send_data():
global data
print('gonna send req here')
while True:
while data:
d = data.pop(0)
print('This one Going', list(d.keys())[0], list(d.values())[0])
request.put_request(list(d.keys())[0], list(d.values())[0])
print('Left over', data)
utime.sleep(0.5)
utime.sleep(1)
Line 104 request.put_request('0113A70CA811', {'24/02/2023':[]})
Line 10 response = urequests.put(url, data=json.dumps(json_data), headers=headers)
Line 188 def put(url, **kw): return request("PUT", url, **kw)
Line 76 ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)