AttributeError : object has no attribute

AttributeError : object has no attribute

我从一个以前的同事那里得到了一个程序,现在应该维护它。 此 python 脚本使用给定的 jql(在 API 上)询问我们的 Jira 实例。 return 是与搜索条件匹配的所有问题的列表。 但现在它不起作用,我在服务器 ( Ubuntu ) 和本地 windows PC 上收到 Json 错误消息。 注意:它 运行 大约一年没有,但当时它有效。

脚本如下所示:

import json
import subprocess

jiraSerachUrl = "https://ourJiraInstance.net/rest/api/2/search?jql=key%20=%20%22TEST-123%22"
jiraResponse = subprocess.Popen(["curl","-l","-s","-u", "jiraUser"+":"+"jiraUserPassword", "-X", "GET", jiraSerachUrl ],stdout=subprocess.PIPE,shell=True).communicate()[0]
## shell=True only added for Windows Instance
print(type(jiraResponse))
##print =  <class 'bytes'>
print(jiraResponse)
## print = b''
jiraJsonResponse = json.loads(jiraResponse.decode('utf-8'))
print(jiraJsonResponse)

jql/jira搜索地址return如下(简答,任务所有字段returned):

{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues": [{"expand":"operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields", "id":"145936","self":"https://ourJiraInstance.net/rest/api/2/issue/145936","key":"TEST-123","fields":{"parent": ...

Windows PC 上的错误如下

Traceback (most recent call last): File "C:\Users\User\Desktop\test.py", line 10, in jiraJsonResponse = json.loads(jiraResponse.decode('utf-8')) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json__init__.py", line 319, in loads return _default_decoder.decode(s) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

这是 Ubuntu 服务器上的错误(运行 相同的脚本)

Traceback (most recent call last): File "searchJira.py", line 33, in jiraJsonResponse = json.loads(jiraResponse) File "/usr/lib/python2.7/json/init.py", line 338, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

到目前为止,我尝试将 Json 负载更改为简单 Json,但结果相同。 更改 Json 应解码的格式(例如 unicode)无效。

试了一下,终于搞定了。通过用响应替换卷曲,我终于得到了我想要的结果。我的请求现在看起来像这样:

r = requests.get(jiraSerachUrl,auth=HTTPBasicAuth(user, password), verify=False) 
jiraJsonResponse=json.loads(r.text)