Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python将0.x代码端口请求为2.x_Python_Python Requests - Fatal编程技术网

Python将0.x代码端口请求为2.x

Python将0.x代码端口请求为2.x,python,python-requests,Python,Python Requests,我有一段非常简单的代码处理Python请求0.x,但当我更新到2.x时,它就不再工作了 代码将返回包含在'field1'中的颜色: import time import requests # Read the thingspeak feed to get the current colour while True: cheerlights = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json

我有一段非常简单的代码处理Python请求0.x,但当我更新到2.x时,它就不再工作了

代码将返回包含在
'field1'
中的颜色:

import time
import requests


# Read the thingspeak feed to get the current colour
while True:
    cheerlights = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json').json['field1']
    print(cheerlights)
time.sleep(16)
当我运行此not时,会出现以下错误:

回溯(最近一次呼叫最后一次): 文件“cheelightsJsonHELP.py”,第7行,在 cheerlights=requests.get(“”).json['field1'] TypeError:“instancemethod”对象没有属性“getitem

我已经阅读了关于从0.x迁移到2.x的文档,但不幸的是,这不是我的一个重点领域,有人能帮忙吗?

现在是一种方法,而在过去它是一种属性;添加
()
以调用它:

response = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json')
cheerlights = response.json()['field1']
演示:

现在是一种方法,过去它是一种属性;添加
()
以调用它:

response = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json')
cheerlights = response.json()['field1']
演示:

现在是一种方法,过去它是一种属性;添加
()
以调用它:

response = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json')
cheerlights = response.json()['field1']
演示:

现在是一种方法,过去它是一种属性;添加
()
以调用它:

response = requests.get('http://api.thingspeak.com/channels/1417/field/1/last.json')
cheerlights = response.json()['field1']
演示:


非常感谢你的帮助,效果非常好!非常感谢你的帮助,效果非常好!非常感谢你的帮助,效果非常好!非常感谢你的帮助,效果非常好!