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