Getting error [ AttributeError: 'bool' object has no attribute 'error' ] when trying to get data using Jira Python API

Getting error [ AttributeError: 'bool' object has no attribute 'error' ] when trying to get data using Jira Python API

python --version
Python 3.8.0

只是想得到一些 issues.fields

from jira import JIRA

def main():
   options = {'server':"https://jira.test.com/" }
   jira = JIRA(options, basic_auth=('username', 'password'))
   issue = jira.issue('XXXX-10085')
   print (issue.fields.project.key)
   print (issue.fields.issuetype.name)
   print (issue.fields.reporter.displayName)
   print (issue.fields.summary)
   print (issue.fields.project.id)

if __name__== "__main__" :
     main()

但我得到错误:

WARNING:root:Bug https://jira.atlassian.com/browse/JRA-59676 trying again...
WARNING:root:Bug https://jira.atlassian.com/browse/JRA-59676 trying again...
WARNING:root:Bug https://jira.atlassian.com/browse/JRA-59676 trying again...
Traceback (most recent call last):
  File "/Users/syedahmed/ANACONDA/anaconda3/envs/jira/lib/python3.8/site-packages/jira/client.py", line 474, in __init__
    self._version = tuple(si['versionNumbers'])
KeyError: 'versionNumbers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "jt.py", line 14, in <module>
    main()
  File "jt.py", line 5, in main
    jira = JIRA(options, basic_auth=('username', 'password'))
  File "/Users/syedahmed/ANACONDA/anaconda3/envs/jira/lib/python3.8/site-packages/jira/client.py", line 476, in __init__
    logging.error("invalid server_info: %s", si)
AttributeError: 'bool' object has no attribute 'error'

@Prabhat 似乎没有得到 REST 的版本号 API 因为当我查看源代码时 ( client.py )

 self.deploymentType = None
 470         if get_server_info:
 471             # We need version in order to know what API calls are available or not
 472             si = self.server_info()
 473             try:
 474                 self._version = tuple(si['versionNumbers'])
 475             except Exception as e:
 476                 logging.error("invalid server_info: %s", si)
 477                 raise e
 478             self.deploymentType = si.get('deploymentType')
 479         else:
 480             self._version = (0, 0, 0)

在浏览器中,当我打开 https://jira.test.com/rest/api/2/issue/XXXX-10085

时得到正确的 JSON

但是当我使用 curl 时,我得到 AUTHENTICATION_DENIED

$ curl -D- -X GET -H "Authorization: Basic base64encodedhash" -H "Content-Type: application/json" "https://jira.test.com/rest/api/2/issue/XXXX-10085"
HTTP/1.1 200
X-AREQUESTID: 1239x574427x1
X-ANODEID: node2
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-ASEN: SEN-6742665
Set-Cookie: JSESSIONID=487ECA3C5601199AB97294A8BA866151; Path=/; HttpOnly
X-Seraph-LoginReason: AUTHENTICATION_DENIED
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Tue, 31 Dec 2019 01:39:14 GMT
Set-Cookie: BIGipServerJIRA=67143434.36895.0000; path=/; Httponly; Secure
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
Set-Cookie: TS01dc5b77=015efd37d830c3fc1357c099281a755d6a9e2fc387d6a6c5af8aead0625e8a81e65afe21e442cd23510d7f30577b4ec345e82490c436146235e475a8d6f0a92a1e4159712c3ac6e13dbe26719fd07ac6ec48b466bd; Path=/

请记住,我正在为 username:password

使用 base64 哈希

URL 并且用户凭据似乎不是 wrong.Check 您尝试访问的服务器和凭据详细信息。

options = {'server':"https://jira.test.com/" }
jira = JIRA(options, basic_auth=('username', 'password'))

参考:https://community.atlassian.com/t5/Jira-questions/How-do-I-access-the-hosted-Jira-API-via-python/qaq-p/505632

自 2019 年 6 月起,Jira 现已弃用标准基本身份验证。

基本身份验证需要 API 密钥,现在取代了 'password' 要求。 API 密钥可以从以下位置生成:https://confluence.atlassian.com/cloud/api-tokens-938839638.html.

获得密钥后,将当前的 Jira 对象替换为以下内容: jira = JIRA(basic_auth=("enter username", "enter API key"), options={'server': "enter server"}).