registerups.py: remove unneeded code
and add connection exception handling
This commit is contained in:
parent
9317eb30b9
commit
c2750889e1
|
@ -18,10 +18,7 @@ class cps_ups:
|
||||||
for i in ET.fromstring(self.connection.getresponse().read()).iter("data"):
|
for i in ET.fromstring(self.connection.getresponse().read()).iter("data"):
|
||||||
keepalive_data=i.attrib
|
keepalive_data=i.attrib
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
result = {'boot': keepalive_data['boot'],
|
return(keepalive_data)
|
||||||
'upt': keepalive_data['upt'],
|
|
||||||
'id': keepalive_data['id']}
|
|
||||||
return(result)
|
|
||||||
def __genxml__(self, keepalive_data):
|
def __genxml__(self, keepalive_data):
|
||||||
data_tag = '<data ver="1.1"'\
|
data_tag = '<data ver="1.1"'\
|
||||||
'hash="hmac-md5-128" '\
|
'hash="hmac-md5-128" '\
|
||||||
|
@ -63,8 +60,12 @@ class cps_ups:
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
self.location = location
|
self.location = location
|
||||||
self.bedt = bedt
|
self.bedt = bedt
|
||||||
post_data = self.__genxml__(self.__get_keepalive_data__())
|
try:
|
||||||
self.connection.request("POST", "/setup.xml", body = post_data)
|
post_data = self.__genxml__(self.__get_keepalive_data__())
|
||||||
|
self.connection.request("POST", "/setup.xml", body = post_data)
|
||||||
|
except (OSError, ConnectionError) as err:
|
||||||
|
print('Unable to register: ' + str(err))
|
||||||
|
sys.exit(3)
|
||||||
response = self.connection.getresponse().read()
|
response = self.connection.getresponse().read()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
return(response)
|
return(response)
|
||||||
|
|
Loading…
Reference in New Issue