PYTHON ERROR AFTER SEVERAL SUCCESSFUL WRITES TO THINGSPEAK CHANNEL | Raspberry Pi | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
PYTHON ERROR AFTER SEVERAL SUCCESSFUL WRITES TO THINGSPEAK CHANNEL
Avatar
perry
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
1
April 30, 2016 - 9:46 pm
sp_Permalink sp_Print

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

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
2
May 1, 2016 - 10:04 pm
sp_Permalink sp_Print

Can you get a stacktrace for the error? 

either

a) comment out the "except urllib2.URLError" section and run it manually

or

b) include stacktrace in your error log see https://docs.python.org/2/library/traceback.html

 

That might give you more information on the failure. 

It may be that this is a temporary network error or time-out and that you have to have your program wait and re-try.

Avatar
perry
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
3
May 4, 2016 - 2:22 am
sp_Permalink sp_Print

Thank you. I will try a trace back. How would I make the program wait and re-try.?

Avatar
walshmagger
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
4
October 6, 2017 - 2:57 am
sp_Permalink sp_Print
Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

donj51

trilee

Bfletche

stuartWAI

shivmkatiyar

AidanThing

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee