繁体   English   中英

尝试使用 Jira Python API 获取数据时出现错误 [AttributeError: 'bool' object has no attribute 'error']

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

python --version
Python 3.8.0

只是想解决一些问题。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=/

请记住,我使用 base64 哈希作为用户名:密码

URL 和用户凭据似乎没有错。检查您尝试访问的服务器和凭据详细信息。

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 密钥,现在取代了“密码”要求。 API 密钥可以从: https : //confluence.atlassian.com/cloud/api-tokens-938839638.html生成。

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

暂无
暂无

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

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