我遇到错误 AttributeError:“响应”对象的以下代码没有属性“获取”
def convert_json(self,bucket,userid,imgfilename,field,i):
bucketName = bucket
link = "users_"+str(userid)+'/'+imgfilename
c = S3Connection(self.AWS_ACCESS_KEY_ID,self.AWS_ACCESS_KEY_SECRET)
p = c.generate_url(expires_in=long(7200),method='GET',bucket=bucketName,key=link,query_auth=True,force_http=False)
post_url = "http://someurl"
wrapper = {"filename":p}
try:
response = requests.post(post_url, json=wrapper)
print response
if response.status_code == 200:
text = response.get('description', [])
else:
text = []
except Exception:
if response.status_code == 200:
text = response.get('description', [])
else:
text = []
return text
答案 0 :(得分:1)
假设您正在使用Requests
库,则Response对象没有get
方法。
给出的链接说明了Response
对象的属性和方法。
答案 1 :(得分:0)
引用requests
page上给出的示例:
>>> import requests
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'disk_usage': 368627, u'private_gists': 484, ...}
该对象不是字典,因此不能使用get
。您可能会找到所需的东西: