gpt4 book ai didi

Python 类型错误 : 'Response' object has no attribute 'getitem'

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:16 25 4
gpt4 key购买 nike

我有这段代码给了我错误消息:

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' object has no attribute 'getitem'

有人可以帮助我吗?

最佳答案

要检查 get() 的状态代码或任何请求,您需要检查响应的 status_code,因此需要将 if user_info['meta']['code'] == 200: 替换为如果 user_info.status_code == 200:

关于Python 类型错误 : 'Response' object has no attribute 'getitem' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47125028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com