From c557c88898fea1aaeb06dff23a8b2b4132b95521 Mon Sep 17 00:00:00 2001 From: Rixillo Date: Thu, 30 Mar 2017 18:24:27 -0700 Subject: [PATCH] Update client.py At first attemp, I put the file in the wrong directory. --- amt/client.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/amt/client.py b/amt/client.py index 555529d..2b6f8ab 100755 --- a/amt/client.py +++ b/amt/client.py @@ -81,19 +81,26 @@ def __init__(self, address, password, username='admin', protocol='http'): self.password = password def post(self, payload, ns=None): - resp = requests.post(self.uri, - headers={'content-type': - 'application/soap+xml;charset=UTF-8'}, - auth=HTTPDigestAuth(self.username, self.password), - data=payload) - resp.raise_for_status() - if ns: - rv = _return_value(resp.content, ns) - if rv == 0: - return 0 - print(pp_xml(resp.content)) - else: - return 0 + try: + resp = requests.post(self.uri, + headers={'content-type': + 'application/soap+xml;charset=UTF-8'}, + auth=HTTPDigestAuth(self.username, self.password), + data=payload, + timeout=5.0) + resp.raise_for_status() + except requests.exceptions.Timeout: + print "Request timed out." + except requests.exceptions.RequestException as e: + print e + else: + if ns: + rv = _return_value(resp.content, ns) + if rv == 0: + return 0 + print(pp_xml(resp.content)) + else: + return 0 def power_on(self): """Power on the box."""