After several successful writes to my thingspeak channel, an error will occur
log = log + 'Failed to reach server. Reason: ' + e.reason
Typeerror: cannot concatenate 'str' and SSLError'objects
I am using raspberry pi's and an odroid w. I receive the error when sending data individually to a channel and when sending to one channel from each pi and the ordroid w. I don't know how to resolve this error or the cause.
I have 1 raspberry pi that has been sending weather data and cpu temperature to a channel with no errors. When I used another python program to send CPU temperature separately to another channel the error occurs after several successful attempts.
import os
import time
import urllib # thinkspeak
import urllib2
import sys # thinkspeak
# --------- User Settings ---------
PI_NAME = "wx Pi"
MINUTES_BETWEEN_READS = 15
THINGSPEAKKEY = 'MYKEY'
THINGSPEAKURL = 'https://api.thingspeak.com/update'
# ---------------------------------
def sendData(url,key,field7,odroid):
"""
Send event to internet site
"""
values = {'key' : key,'field7' : odroid}
postdata = urllib.urlencode(values)
req = urllib2.Request(url, postdata)
log = time.strftime("%m-%d-%Y,%H:%M:%S") + ", "
log = log + "{:.2f}F".format(odroid) + ", "
try:
# Send data to Thingspeak
response = urllib2.urlopen(req, None, 1)
html_string = response.read()
response.close()
log = log + 'Update ' + html_string
except urllib2.HTTPError, e:
log = log + 'Server could not fulfill the request. Error code: ' + e.code
except urllib2.URLError, e:
log = log + 'Failed to reach server. Reason: ' + e.reason
except:
log = log + 'Unknown error'
print log
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C
",""))
def main():
while True:
cpuTemp = int(float(getCPUtemperature()))
cpuTemp_f = cpuTemp * 9.0 / 5.0 +32
cpuTemp_f = float("{0:.2f}".format(cpuTemp_f))
curTime = time.strftime("%m-%d-%Y,%H:%M:%S")
# Print and stream
print PI_NAME + " CPU Temp(F): " + str(cpuTemp_f)
print PI_NAME + " current Time: " + str(curTime)
sendData(THINGSPEAKURL,THINGSPEAKKEY,'field7',cpuTemp_f)
sys.stdout.flush()
time.sleep(60*MINUTES_BETWEEN_READS)
if __name__ == "__main__":
main()
Thank you Perry