This commit is contained in:
Bridget
2020-04-13 16:00:17 +02:00
parent 6c53b8ab83
commit 4f0dea7449

8
lib.py
View File

@@ -19,15 +19,12 @@ def send_cmd(url: str, secret_key: str, cmd: str) -> Dict:
try:
response = requests.post(url, json=data, verify=False)
response.raise_for_status()
response_data = response.json()
except (
requests.ConnectionError,
requests.exceptions.MissingSchema,
requests.exceptions.InvalidURL,
):
raise requests.exceptions.InvalidURL
except JSONDecodeError:
raise Exception("Error: Response has malformed json")
except requests.exceptions.HTTPError as e:
if e.response.status_code == 423:
error_msg = e.response.json().get("error")
@@ -35,6 +32,11 @@ def send_cmd(url: str, secret_key: str, cmd: str) -> Dict:
else:
raise e
try:
response_data = response.json()
except JSONDecodeError:
raise Exception("Error: Response has malformed json")
error = response_data.get("error", None)
if error:
raise ErrorReceived(f"Error: {error}")