我有这段代码给我错误信息:
import requests
BASE_URL = 'https://api.instagram.com/v1'
response = requests.get('https://jsonbin.io/b/59d0f30408be13271f7df29c').json()
APP_ACCESS_TOKEN = response['access_token']
print APP_ACCESS_TOKEN
def self_info():
request_url = (BASE_URL + 'users/self/?access_token=%s') % (APP_ACCESS_TOKEN)
print 'GET request url : %s' % (request_url)
user_info = requests.get(request_url)
if user_info['meta']['code'] == 200:
print 'tabish'
else:
print 'Status code other than 200 received!'
self_info()
这会导致以下错误消息:
TypeError:'Response'对象没有属性' getitem '
任何人都可以帮助我吗?
答案 0 :(得分:1)
要检查get()的状态代码或检查响应的status_code所需的任何请求,因此您需要将if user_info['meta']['code'] == 200:
替换为if user_info.status_code == 200:
。