2017-10-25 3 views
0

MicroPythonを実行しているESP8266 MCUから(Android)モバイルデバイスの通知を受信しようとしています。この理由から私は、この仕事のいくつかのAPI、Pushbullet、およびPushを公開しているいくつかのオンラインサービスを購読し、デバイスに一致するアプリをインストールしました。MicroPython urequests.postの失敗

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 

これらのエラーを検索しても、どこでも役に立たなくなります。

まったく同じコードスニペットは、(代わりにurequestsrequestsを使用して)私のLinuxボックスで[OK]を動作しますが、私はurequestsはいくつかの制限を有することができることを理解しています。

これを修正する方法に関するヒントはありますか?

答えて

0

例外メッセージは、urequestsが期待していない種類のデータを渡すことを示唆しています。 HTTP POSTがどのように動作するかについての私の知識(HTTP標準参照)から、私はそれがstrまたはbytesタイプで表されるオクテットストリームを受け入れることを知っています。一方、あなたは辞書を渡します。 `

+0

Micropythonフォーラムで私が答えたところによると、これは" Pushbul "のスニペットでは、私は"プッシュ "の例(これについてはまだ解決していませんでした) @ https://github.com/micropython/micropython/issues/3389で提案されているように、Micropythonと 'urequests'モジュールの毎日のビルドへのアップグレードを通知しました。 – dentex