简体   繁体   English

AttributeError:对象没有属性

[英]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 ). 这个python脚本向我们的Jira实例询问给定的jql(在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. 但是现在它不起作用了,我在服务器(Ubuntu)和本地Windows PC上收到一条Json错误消息。 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): jql / jira搜索地址返回以下内容(简短回答,将返回任务的所有字段):

{"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": ... {“ expand”:“名称,模式”,“ startAt”:0,“ maxResults”:50,“ total”:1,“ issues”:[{“ expand”:“ operations,versioned Representations,editmeta,changelog,transitions, renderingFields“,” id“:” 145936“,” self“:” https://ourJiraInstance.net/rest/api/2/issue/145936 “,” key“:” TEST-123“,” fields“:{ “父母”:...

The Error on the Windows PC is the following 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) 追溯(最近一次通话):文件“ C:\\ Users \\ User \\ Desktop \\ test.py”,第10行,位于jiraJsonResponse = json.loads(jiraResponse.decode('utf-8'))文件“ C:\\负载中的“ Users \\ User \\ AppData \\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ json__init __。py”第319行返回_default_decoder.decode文件“ C:\\ Users \\ User \\ AppData \\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ json \\ decoder.py”,行339,在解码obj中,end = self.raw_decode(s,idx = _w(s,0).end())文件“ C:\\ Users \\在Raw_decode中,User \\ AppData \\ Local \\ Programs \\ Python \\ Python35-32 \\ lib \\ json \\ decoder.py“行357从None json.decoder.JSONDecodeError引发JSONDecodeError(” Expecting value“,s,err.value):期望值:第1行第1列(字符0)

This is the error on the Ubuntu Server ( running the same script ) 这是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 追溯(最近一次通话最近):jiraJsonResponse = json.loads(jiraResponse)中的文件“ searchJira.py”,第33行,加载中的文件“ /usr/lib/python2.7/json/ init .py”,第338行返回_default_decoder.decode(s)文件“ /usr/lib/python2.7/json/decoder.py”,行366,在解码obj中,end = self.raw_decode(s,idx = _w(s,0).end ())raw_decode中的文件“ /usr/lib/python2.7/json/decoder.py”,第384行,引发ValueError(“无法解码JSON对象”)ValueError:无法解码JSON对象

So far I tried to change the Json load to simpleJson, but with the same result. 到目前为止,我尝试将Json负载更改为simpleJson,但结果相同。 Changing the format to which Json should decode ( eg unicode ) took no effect. 更改Json应该解码的格式(例如unicode)无效。

I have tried a bit and finaly got it. 我尝试了一下,最后得到了它。 by replacing curl with responses i got finally the result I wanted. 通过用响应替换curl,我终于得到了想要的结果。 my request looks now like this : 我的请求现在看起来像这样:

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

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

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