Dip*_*Das 9 attributeerror python-2.7
我收到错误 AttributeError: 'Response' object has no attribute 'get' 对于我编写的以下代码
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
Run Code Online (Sandbox Code Playgroud)
Use*_*716 10
该对象不是字典,因此您不能使用get. 您可能会通过以下任一方式找到所需内容:
引用requests 页面上给出的示例:
>>> 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, ...}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33600 次 |
| 最近记录: |