using raspberry py 4 with python 3.9
Latest activity Reply by Jos Spronk
on 14 Nov 2022
Hello
I am Jos
i have made a program for upload data to mine channels in pytython 2.7, now I am forced to go to 3.9 and I cannot get the program running
code for 2.7
import httplib
import urllib
def WriteData():
while True:
params = urllib.urlencode({'key': 'xxxxxxxxxxxxxxxx', 'field1': '0.021'})
headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80")
try:
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print (response.status, response.reason)
data = response.read()
conn.close()
except:
print ("connection failed")
break
can someone help me with this code?
5 Comments
Time DescendingHello Christopher
is there an example for writing multiple channels in python 3.9?
now I can write one channel but I can not find a way for multiple channels
this is the code
baseURL = 'http://api.thingspeak.com/update?api_key=C2MDJO6H1F4JPTG4&field1='
f = urllib.request.urlopen(baseURL +str(cpu_percent))
f.read()
f.close
sleep(0.5)
please help me out
What is the output when you use it in 3.9? What error do you see?
Sign in to participate