简体   繁体   English

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

[英]What does this stack trace from python requests indicate?

I am trying to make a requests call to elasticsearch, I can make this exact same call from a plain script, but if I set a list as a string and pass to the payload, I am getting this stack trace: 我正在尝试对Elasticsearch进行请求调用,我可以从普通脚本中进行完全相同的调用,但是如果我将列表设置为字符串并传递给有效负载,则会得到此堆栈跟踪:

I am trying to pass a list as a string to a curl post and python seems to be breaking. 我试图将列表作为字符串传递给curl帖子,而python似乎坏了。 Please help. 请帮忙。

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)
#########

I should be getting back a list of jsons (Dictionaries) 我应该找回jsons列表(字典)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM