I'm trying to get a program to push a notification to my phone via pushbullet. I found some code that supposedly works(or worked at some time) and get an error:
File "C:\Users\jobla\Documents\Micropython-Projects\workSpace\RNT-ESP32-ESP8266\visitorpush.py", line 87, in <module>
File "C:\Users\jobla\Documents\Micropython-Projects\workSpace\RNT-ESP32-ESP8266\visitorpush.py", line 63, in visitornotify
File "/lib/urequests.py", line 115, in post
File "/lib/urequests.py", line 68, in request
TypeError: object with buffer protocol required
The relevant request is:
def visitornotify():
r = urequests.post(
'https://api.pushbullet.com/v2/pushes',
#data=json.dumps(data_sent),
#'Host':'api.pushbullet.com',
data=data_sent,
headers=pb_headers)
Line 53 is the 'https....' line.
data_sent = {"type": "note", "title": title, "body": body}
Don't know how to fix this...anyone have some wisdom to share on this?
Thanks.
urequests object with buffer protocol required
-
- Posts: 9
- Joined: Sun Nov 11, 2018 8:11 pm
Re: urequests object with buffer protocol required
try:
json.dumps will be called on the json parameter by urequests.
otherwise data takes bytes, not a string, so you need to encode the data
Code: Select all
urequest.post(url, json=data_send)
otherwise data takes bytes, not a string, so you need to encode the data
Code: Select all
urequests.post(url, data=json.dumps(data_send).encode('utf-8'))