来自python请求的堆栈跟踪说明了什么?

时间:2019-01-23 01:09:31

标签: python python-requests

我正在尝试对elasticsearch进行请求调用,我可以从普通脚本中进行完全相同的调用,但是如果我将列表设置为字符串并传递给有效负载,则会得到此堆栈跟踪:

我正在尝试将列表作为字符串传递给curl帖子,而python似乎正在中断。请帮忙。

Traceback (most recent call last):
File "moodgb.py", line 79, in <module>
    print(response.text)
File "/usr/lib/python2.7/site-packages/requests/models.py", line 760, in text
    if not self.content:
File "/usr/lib/python2.7/site-packages/requests/models.py", line 733, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/usr/lib/python2.7/site-packages/requests/models.py", line 656, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/usr/lib/python2.7/site-packages/urllib3/response.py", line 273, in stream
    data = self.read(amt=amt, decode_content=decode_content)
File "/usr/lib/python2.7/site-packages/urllib3/response.py", line 186, in read
    self._decoder = _get_decoder(content_encoding)
File "/usr/lib/python2.7/site-packages/urllib3/response.py", line 57, in _get_decoder
    return GzipDecoder()
File "/usr/lib/python2.7/site-packages/urllib3/response.py", line 44, in __init__
    self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS)
ValueError: Invalid initialization option

Here is the code:
#########
c=str(sorted(set(mysql_alertids)))
#test = str(mysql_alertids)

url = "http://elastic:9900/index%2A/_search"

payload = "{\"size\":10000,\r\n\t\"query\": \r\n\t{\r\n\t\t\"terms\" :\r\n\t\t{\r\n\t\t\t\"alert_id\" : "+c+" \r\n\t\t}\r\n\t}\r\n}"
print(payload)
headers = {
    'content-type': "application/json",
    'authorization': "val",
    'cache-control': "no-cache",
    'postman-token': "token"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
#########

我应该找回jsons(词典)列表

1 个答案:

答案 0 :(得分:1)

有趣..添加导入zlib解决了该问题!