try/except when post
This commit is contained in:
parent
15a27bc8ff
commit
1d16899296
2 changed files with 20 additions and 8 deletions
esp8266
|
@ -1,5 +1,5 @@
|
|||
from machine import Pin
|
||||
from urequests import get, post
|
||||
import urequests as requests
|
||||
from time import sleep_ms
|
||||
from gc import collect
|
||||
from uConfigParser import ConfigParser
|
||||
|
@ -18,14 +18,26 @@ while True:
|
|||
try:
|
||||
url = config[section]['url']
|
||||
method = config[section]['method']
|
||||
|
||||
except:
|
||||
print("error when read section %s in config file" % section)
|
||||
else:
|
||||
continue
|
||||
data = {option:config[section][option] for option in config_obj.options(section) if not 'url' in option or not "method" in option}
|
||||
if method == "POST":
|
||||
post(url, **data)
|
||||
elif method == "GET":
|
||||
get(url, **data)
|
||||
data = {option:config[section][option] for option in config_obj.options(section)}
|
||||
del data['url']
|
||||
del data['method']
|
||||
try:
|
||||
if method == "GET":
|
||||
print('GET')
|
||||
r = requests.get(url, data=data)
|
||||
elif method == "POST":
|
||||
print('POST')
|
||||
r = requests.post(url, data=data)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
print("close")
|
||||
r.close()
|
||||
print("closed")
|
||||
pin_value = current_value
|
||||
collect()
|
||||
|
|
|
@ -4,8 +4,8 @@ class ConfigParser:
|
|||
|
||||
def sections(self):
|
||||
"""Return a list of section names, excluding [DEFAULT]"""
|
||||
dict_to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"]
|
||||
return dict_to_return
|
||||
to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"]
|
||||
return to_return
|
||||
|
||||
def add_section(self, section):
|
||||
"""Create a new section in the configuration."""
|
||||
|
|
Loading…
Reference in a new issue