这是我的密码
import os
import glob
import time
import sys
import datetime
import urllib2
baseURL = "https://api.thingspeak.com/update?api_key=DCL2IZ1REQT5GUSM"
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = 'sys/bus/w1/devices/'
#Temp1 temperature device location
temp1_file = '/sys/bus/w1/devices/28-0000087787c4/w1_slave'
#Temp2 temperature Device Location
temp2_file = '/sys/bus/w1/devices/28-000008762fa3/w1_slave'
#Determine Temp1 Temperature
def read_rawtemp_temp1():
y = open(temp1_file,'r')
lines = y.readlines()
y.close
return lines
def read_temp_temp1():
lines = read_rawtemp_temp1()
while lines[0].strip()[-3:] !='YES':
time.sleep(0.2)
lines = read_rawtemp_temp1()
equals_pos = lines[1].find('t=')
if equals_pos !=-1:
temp_string = lines[1][equals_pos+2:]
temp_temp1 = ((float(temp_string)/1000.0)*1.8)-32
return temp_temp1
#Determine Temp2 Temperature
def read_rawtemp_temp2():
x = open(temp2_file,'r')
lines = x.readlines()
x.close
return lines
def read_temp_temp2():
lines = read_rawtemp_temp2()
while lines[0].strip()[-3:] !='YES':
time.sleep(0.2)
lines = read_rawtemp_temp1()
equals_pos = lines[1].find('t=')
if equals_pos !=-1:
temp_string = lines[1][equals_pos+2:]
temp_temp2 = float(temp_string)/1000.0
return temp_temp2
while True: #Loop
#Send Temp1 Temperature to Thingspeak
temp1_tempin = read_temp_temp1()
#Send temp2 temperature to Thingspeak
temp2_tempin = read_temp_temp2()
#Pull results together
values = [datetime.datetime.now(), temp1_tempin, temp2_tempin]
#Open Thingspeak channel and assign fields to temperatures
j = urllib2.urlopen(baseURL + "&field1=%s" % (temp1_tempin) + "&field2=%s" % (temp2_tempin))
try:
search_response = urllib2.urlopen(search_request)
except urllib2.HTTPError:
pass
#Time to next loop
time.sleep(600)
下面是一个错误,它将在几个小时后停止脚本的运行。在
Traceback (most recent call last):
File "tempdatalog.py", line 137, in <module>
j = urllib2.urlopen(baseURL + "&field1=%s" % (temp1_tempin) +
"&field2=%s" % (temp2_tempin))
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
我补充道:
^{pr2}$这是想让它忽略错误,但没用。任何建议,将是伟大的,这只是一个开始的监测医疗系统在移动。在
看看您的stacktrace,您似乎在
try/except
子句中换行了。在此版本至少捕获异常:
这仍然不能解释为什么错误首先出现。我猜是一种利率限制
相关问题 更多 >
编程相关推荐