[英]JIRA access using REST API decompressing data error
我正在嘗試使用 python 與 JIRA API 合作。 我已使用此頁面中的示例https://www.opentechguides.com/how-to/article/python/185/jira-python-rest.html
總的來說,在我更改過濾器之前它起作用了
項目 = PKY 到項目 = INN 和類型 = Epic
我收到以下錯誤
Traceback (most recent call last): File "D:\work\py\jirafirst\venv\lib\site-packages\urllib3\response.py", line 388, in _decode
data = self._decoder.decompress(data) File "D:\work\py\jirafirst\venv\lib\site-packages\urllib3\response.py", line 85, in decompress
ret += self._obj.decompress(data) zlib.error: Error -3 while decompressing data: incorrect header check
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "D:\work\py\jirafirst\venv\lib\site-packages\requests\models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True): File "D:\work\py\jirafirst\venv\lib\site-packages\urllib3\response.py", line 564, in stream
data = self.read(amt=amt, decode_content=decode_content) File "D:\work\py\jirafirst\venv\lib\site-packages\urllib3\response.py", line 536, in read
data = self._decode(data, decode_content, flush_decoder) File "D:\work\py\jirafirst\venv\lib\site-packages\urllib3\response.py", line 391, in _decode
raise DecodeError( urllib3.exceptions.DecodeError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "D:/work/py/jirafirst/1.py", line 21, in <module>
response = requests.request( File "D:\work\py\jirafirst\venv\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs) File "D:\work\py\jirafirst\venv\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs) File "D:\work\py\jirafirst\venv\lib\site-packages\requests\sessions.py", line 686, in send
r.content File "D:\work\py\jirafirst\venv\lib\site-packages\requests\models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' File "D:\work\py\jirafirst\venv\lib\site-packages\requests\models.py", line 755, in generate
raise ContentDecodingError(e) requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))
樣本
import requests
import json
import base64
# Base encode email and api token
cred = "Basic " + base64.b64encode(b'myemail@otg.com:pQcIDzMucUS76VBUmwzp2012').decode("utf-8")
# Set header parameters
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization" : cred
}
# Enter your project key here
projectKey = "PKY"
# Update your site url
url = "https://mysite.atlassian.net/rest/api/2/search?jql=project=" + projectKey
# Send request and get response
response = requests.request(
"GET",
url,
headers=headers
)
# Decode Json string to Python
json_data = json.loads(response.text)
# Display issues
for item in json_data["issues"]:
print(item["id"] + "\t" + item["key"] + "\t" +
item["fields"]["issuetype"]["name"] + "\t" +
item["fields"]["created"]+ "\t" +
item["fields"]["creator"]["displayName"] + "\t" +
item["fields"]["status"]["name"] + "\t" +
item["fields"]["summary"] + "\t"
)
通過將'Accept-Encoding': 'identity'
放入請求的標頭中解決了這個問題。 同樣的方法適用於 JIRA 庫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.