我该如何修复ChunkedEncodingError?

时间:2016-11-09 16:44:30

标签: python google-app-engine python-requests

我收到此错误 ChunkedEncodingError :('连接中断:IncompleteRead(读取14个字节)',IncompleteRead(读取14个字节))
我正在从"请求"发出POST请求。使用python在Google App Engine中的库(第三方)。

url = 'https://fcm.googleapis.com/fcm/send'
        body = {
            "data": {
                "title": "data:mytitle",
                "body": "data:mybody",
                "url": "data:myurl"
            },
            "notification": {
                "title": "noti:My web app name",
                "body": "noti:message",
                "content_available": "noti:true"
            },
            "message": "test",
            "registration_ids": ["xxxxxxxxxxxxxxxxxxxx"]
        }
        headers = {"Content-Type": "application/json",
                   "Authorization": "key=xxxxxxxxxxxxxxxx"}

        logging.error(json.dumps(body))
        requests.post(url, data=json.dumps(body), headers=headers)

2 个答案:

答案 0 :(得分:2)

Google App Engine的问题在于,我们不能单独处理“请求”,我们还需要使用“requests-toolbelt”。

第1步:将request-toolbelt添加到appDIR / lib
https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library


第2步:在main.py内添加

import requests_toolbelt.adapters.appengine

requests_toolbelt.adapters.appengine.monkeypatch()


这将解决问题。

答案 1 :(得分:1)

我遇到过这个问题而且我使用了PyFCM。一切正常。如果您愿意使用它,请确保安装1.2.8或更高版本。下面的任何版本都会导致您遇到同样的问题

相关问题