TypeError: not all arguments converted during string formatting ( Data upload to thinkspeak)
TypeError: not all arguments converted during string formatting ( Data upload to thinkspeak)
我是 python 的新手,我在使用这段代码时遇到了问题
import time
import requests
temp = [12,13,14,15,16,17,18,19,12,10]
humi = [67,68,69,50,56,57,59,59,45,48]
for x in range(10):
print ('Uploading sample',x,'...')
resp=requests.get('https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0' %(temp[x],humi[x]))
time.sleep(20)
字符串格式
>>> "Hi I am %s and I am %d years old"%("PSKP", 22)
Hi I am PSKP and I am 22 years old
喜欢使用这种字符串格式。表示您在括号中的 %
之后传递的参数必须匹配该字符串中的 %s
%d
。
在你的例子中,sting https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0
没有任何可以用给定值填充的位置。
如果您分享 API 有问题的调用格式,我们可以弄清楚如何使用它? ;-)
编辑
import time
import requests
temp = [12,13,14,15,16,17,18,19,12,10]
humi = [67,68,69,50,56,57,59,59,45,48]
for x in range(10):
print ('Uploading sample',x,'...')
resp=requests.get('https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0&temp=%d&humi=%d' %(temp[x],humi[x]))
time.sleep(20)
这是有效的
我是 python 的新手,我在使用这段代码时遇到了问题
import time
import requests
temp = [12,13,14,15,16,17,18,19,12,10]
humi = [67,68,69,50,56,57,59,59,45,48]
for x in range(10):
print ('Uploading sample',x,'...')
resp=requests.get('https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0' %(temp[x],humi[x]))
time.sleep(20)
字符串格式
>>> "Hi I am %s and I am %d years old"%("PSKP", 22)
Hi I am PSKP and I am 22 years old
喜欢使用这种字符串格式。表示您在括号中的 %
之后传递的参数必须匹配该字符串中的 %s
%d
。
在你的例子中,sting https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0
没有任何可以用给定值填充的位置。
如果您分享 API 有问题的调用格式,我们可以弄清楚如何使用它? ;-)
编辑
import time
import requests
temp = [12,13,14,15,16,17,18,19,12,10]
humi = [67,68,69,50,56,57,59,59,45,48]
for x in range(10):
print ('Uploading sample',x,'...')
resp=requests.get('https://api.thingspeak.com/update?api_key=WTJJF5W2CL8IGT19&field1=0&temp=%d&humi=%d' %(temp[x],humi[x]))
time.sleep(20)
这是有效的