我试图通过运行MicroPython的ESP8266 MCU在我的(Android)移动设备上接收通知。出于这个原因,我订阅了几个在线服务,为此任务公开了一些API,Pushbullet和Pushed,我在我的设备上安装了匹配的应用程序。
这就是我正在尝试的:
Pushbullet:
import json
import urequests
body = "Test Notification"
title = "Pushbullet"
data_sent = {"type": "note", "title": title, "body": body}
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
pb_headers = {
'Authorization': 'Bearer ' + API_KEY,
'Content-Type': 'application/json'
}
r = urequests.post(
'https://api.pushbullet.com/v2/pushes',
data=json.dumps(data_sent),
headers=pb_headers
)
print(r)
错误:
ssl_handshake_status: -256
Traceback (most recent call last):
File "<stdin>", line 11, in <module>
File "urequests.py", line 104, in post
File "urequests.py", line 56, in request
OSError: [Errno 5] EIO
推:
import json
import urequests
payload = {
"app_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"app_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"target_type": "app",
"content": "Remote Mic MCU test from ESP8266"
}
r = urequests.post("https://api.pushed.co/1/push", data=payload)
print(r)
错误:
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "urequests.py", line 104, in post
File "urequests.py", line 74, in request
TypeError: object with buffer protocol required
搜索这些错误,并不能让我有用。
完全相同的代码段在我的Linux机箱上运行正常(使用requests
代替urequests
),但我了解urequests
可能有一些限制。
你对如何解决这个问题有任何暗示吗?
答案 0 :(得分:0)
异常消息表明您传递了urequests
不期望的数据类型。根据我对HTTP POST如何工作的了解(参见HTTP标准),我知道它接受八位字节流,在Python中它将由str
或bytes
类型表示。而你通过字典。
`