Python 请求无法解码响应

Python 请求无法解码响应,python,python-requests,Python,Python Requests,我想使用python请求从API获取响应。在《邮递员》中,这是有效的。我使用头Content-Type-application/json和正文中的原始json。我如何用python实现这一点 现在我得到以下contentDecodingError 'Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect

我想使用python请求从API获取响应。在《邮递员》中,这是有效的。我使用头
Content-Type-application/json
和正文中的原始json。我如何用python实现这一点

现在我得到以下
contentDecodingError

'Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check')
示例代码

import requests
url = "http://api.semstorm.com/api-v3/monitoring/monitoring-keyword/get-list"
key = "xxxx"
dat = {'services_token' : key, 'campaign_id' : 43174}
hed = {'Content-Type': 'application/json'}


POST = requests.post(url, json = dat, headers = hed)

您的模块需要gzip,但服务器不返回gzip。您可以尝试添加编码类型。我不能保证类型,这取决于您的api

import requests
url = "http://api.semstorm.com/api-v3/monitoring/monitoring-keyword/get-list"
key = "xxxx"
dat = {'services_token' : key, 'campaign_id' : 43174}
hed = {'Content-Type': 'application/json', 'Accept-Encoding': 'deflate'}

POST = requests.post(url, json = dat, headers = hed)

如果我在R中添加encode=c('json'),这对我是有效的

您也在Postman中发出POST请求了吗?您的模块需要gzip,但服务器不返回gzip。在Postman中,我发出了POST。在R(库httr)中,如果我添加encode=c(“json”),这会起作用。