Skip to content

Commit c862722

Browse files
committed
adds check if necessary requests exception class is available bb-Ricardo#298
1 parent 76b9ccf commit c862722

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

module/netbox/connection.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727

2828
log = get_logger()
2929

30+
# test for necessary requests exception class
31+
try:
32+
from requests.exceptions import JSONDecodeError as RequestsJSONDecodeError
33+
except ImportError:
34+
log.error(f"Discovered outdated 'requests' version '{requests.__version__}'. Update of virtual environment needed.")
35+
exit(1)
36+
3037

3138
class NetBoxHandler:
3239
"""
@@ -260,7 +267,7 @@ class definition of the desired NetBox object
260267

261268
try:
262269
result = response.json()
263-
except (json.decoder.JSONDecodeError, requests.exceptions.JSONDecodeError):
270+
except (json.decoder.JSONDecodeError, RequestsJSONDecodeError):
264271
pass
265272

266273
if response.status_code == 200:
@@ -357,7 +364,7 @@ def single_request(self, this_request):
357364
log.debug("Response Body:")
358365
try:
359366
pprint.pprint(response.json())
360-
except json.decoder.JSONDecodeError as e:
367+
except (json.decoder.JSONDecodeError, RequestsJSONDecodeError) as e:
361368
log.error(e)
362369

363370
return response

0 commit comments

Comments
 (0)