Skip to content

Commit f777f66

Browse files
author
mfsoftworks
committed
[script] updated to handle non json response
1 parent 8ead0d9 commit f777f66

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

monitor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def main():
7272
print("\nData:")
7373
print(data)
7474

75-
post_data(data)
75+
send_data(data)
7676

7777
def get_bandwidth():
7878
# Get net in/out
@@ -99,14 +99,18 @@ def get_bandwidth():
9999
network = {"traffic_in" : current_in, "traffic_out" : current_out}
100100
return network
101101

102-
def post_data(data):
102+
def send_data(data):
103103
try:
104104
endpoint = "http://monitor.localhost.local/api/"
105105
response = requests.get(url = endpoint, params = {"data" : data})
106106
print("\nGET:")
107107
print("Response:", response.status_code)
108108
print("Headers:", response.headers)
109-
print("Content:\n", response.json())
109+
print("Content:", response.content)
110+
try:
111+
print("JSON Content:\n", response.json())
112+
except:
113+
print("No JSON content")
110114
except requests.exceptions.RequestException as e:
111115
print("\nGET Error:\n",e)
112116
exit(0)

0 commit comments

Comments
 (0)