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

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





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

sp_Feed sp_TopicIcon
PYTHON ERROR AFTER SEVERAL SUCCESSFUL WRITES TO THINGSPEAK CHANNEL
No permission to create posts
April 30, 2016
9:46 pm
Avatar
perry
New Member
Members
Forum Posts: 2
Member Since:
April 30, 2016
sp_UserOfflineSmall Offline

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

May 1, 2016
10:04 pm
Avatar
rw950431

Top
Members
Forum Posts: 269
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

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.

May 4, 2016
2:22 am
Avatar
perry
New Member
Members
Forum Posts: 2
Member Since:
April 30, 2016
sp_UserOfflineSmall Offline

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

October 6, 2017
2:57 am
Avatar
walshmagger
New Member
Members
Forum Posts: 1
Member Since:
October 6, 2017
sp_UserOfflineSmall Offline
Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
16 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

dollyip18, toddbt2, SatrapB, Ronalpsync, wandaim69, GregoryGof

Administrators: Hans: 387, lee: 457