· 6 years ago · Oct 12, 2019, 08:34 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 params=urllib.urlencode({'field1':a,'key':key})
9
10 headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
11 conn = httplib.HTTPConnection("api.thingspeak.com:80")
12 try:
13 conn.request("POST", "/update", params, headers)
14 response = conn.getresponse()
15 #print( 'sending.....')
16 #print( response.status, response.reason)
17 data = response.read()
18 conn.close()
19 print("sucess")
20 except:
21 print( "connection failed")
22 break