2016-11-09 87 views
1

我收到此錯誤
ChunkedEncodingError:( '斷開的連接:IncompleteRead(14個字節讀)',IncompleteRead(14個字節讀))
我正在從 「請求」 POST請求庫(第三方)在Google App Engine中使用python。
我應該如何修復ChunkedEncodingError?

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

與谷歌應用程序引擎的問題是,一個人不能以「請求」孤獨的工作,我們也需要使用「請求 - 工具區」與它一起。

步驟1:添加請求-工具區到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() 


這將解決這個問題。

+0

這是正確的。 [發出HTTP(S)請求](https://cloud.google.com/appengine/docs/standard/python/issue-requests#issuing_an_http_request)的文檔解釋了包括**請求 - 工具欄**確保**請求**庫使用** URL提取**而不是其默認的套接字。 – Nicholas

+0

This Works!我正在嘗試使用gspread讀取表單並面臨ChunkedEncodingError問題。現在解決了!謝謝 :) –

1

我有這個問題,我用PyFCM。和一切工作。如果你願意使用它,只要確保你安裝了1.2.8或更高版本。以下任何版本將導致您遇到同樣的問題

相關問題