简体   繁体   中英

AttributeError : object has no attribute

I got a program from a formerly colleague and now should maintain it. This python script asks our Jira instance with a given jql ( on the API ). The return is a list of all issues, which are matching the search criteria. But now it's not working, and I receive on the server ( Ubuntu ) and on my local windows PC a Json error message. note : it ran for about a year not, but back then it worked.

Here is what the script looks like :

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)

The jql/jira search address returns the following (shorted answer, all fields of the task are 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": ...

The Error on the Windows PC is the following

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)

This is the error on the Ubuntu Server ( running the same script )

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

So far I tried to change the Json load to simpleJson, but with the same result. Changing the format to which Json should decode ( eg unicode ) took no effect.

I have tried a bit and finaly got it. by replacing curl with responses i got finally the result I wanted. my request looks now like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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