· 6 years ago · Nov 19, 2019, 09:10 AM
1import time
2import httplib
3import urllib
4key="5CGWWYRZNCO7F0SL" #api key
5for i in range(10):
6 a=input("enter the num")
7 print (a)
8 b=input("enter the num")
9 params=urllib.urlencode({'field1':a,'field2':b,'key':key})
10
11 headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
12 conn = httplib.HTTPConnection("api.thingspeak.com:80")
13 try:
14 conn.request("POST", "/update", params, headers)
15 response = conn.getresponse()
16 #print( 'sending.....')
17 #print( response.status, response.reason)
18 data = response.read()
19 conn.close()
20 print("sucess")
21 except:
22 print( "connection failed")