Skip to content

Commit

Permalink
Merge pull request #3 from kirichkov/catch-network-exception
Browse files Browse the repository at this point in the history
Catch network exceptions and return None instead of -1000
  • Loading branch information
SebuZet authored Mar 27, 2019
2 parents e08692f + a587afd commit 3a7dd0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions connection_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ def execute(self, template, value):
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
with requests.sessions.Session() as session:
self.logger.info(self._params)
resp = session.request(**self._params)
self.logger.info("Command executed with code: {}".format(resp.status_code))

try:
resp = session.request(**self._params)
self.logger.info("Command executed with code: {}".format(resp.status_code))
except (requests.exceptions.ConnectionError, OSError):
# OSError is returned when there is no route to the host
resp = None

if resp is not None and resp.ok:
try:
j = resp.json()
Expand Down
2 changes: 1 addition & 1 deletion properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def value(self):
try:
f = float(self._value)
except:
f = -1000
f = None
return f

@property
Expand Down

0 comments on commit 3a7dd0a

Please sign in to comment.