Remove unusable code

Since the Request class catches/re-raises every errors (including
http non-200 status codes) some lines could never be reached. Some
of these lines were already removed in the previous commit.
This commit is contained in:
Max Ziermann
2020-03-04 12:28:04 +01:00
parent 5d4a38f9a2
commit 7512ce40ea
2 changed files with 4 additions and 14 deletions

View File

@@ -122,14 +122,8 @@ class APIHandler:
}}}] }}}]
param = {"token": self.token} param = {"token": self.token}
response = Request.post(self.url, data=body, params=param) response = Request.post(self.url, data=body, params=param)
if response is not None: print("Successfully Set Network Ports")
if response.status_code == 200: return True
print("Successfully Set Network Ports")
return True
else:
print("Something went wront\nStatus Code:", response.status_code)
return False
return False
except Exception as e: except Exception as e:
print("Setting Network Port Error\n", e) print("Setting Network Port Error\n", e)
raise raise
@@ -159,10 +153,7 @@ class APIHandler:
{"cmd": "GetP2p", "action": 0, "param": {}}] {"cmd": "GetP2p", "action": 0, "param": {}}]
param = {"token": self.token} param = {"token": self.token}
response = Request.post(self.url, data=body, params=param) response = Request.post(self.url, data=body, params=param)
if response.status_code == 200: return json.loads(response.text)
return json.loads(response.text)
print("Could not get network ports data. Status:", response.status_code)
return None
except Exception as e: except Exception as e:
print("Get Network Ports", e) print("Get Network Ports", e)
@@ -447,7 +438,6 @@ class APIHandler:
:return: Image or None :return: Image or None
""" """
try: try:
randomstr = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) randomstr = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
snap = self.url + "?cmd=Snap&channel=0&rs=" \ snap = self.url + "?cmd=Snap&channel=0&rs=" \
+ randomstr \ + randomstr \

View File

@@ -28,7 +28,7 @@ class Request:
if r.status_code == 200: if r.status_code == 200:
return r return r
else: else:
raise ValueError("Status: ", r.status_code) raise ValueError(f"Http Request had non-200 Status: {r.status_code}", r.status_code)
except Exception as e: except Exception as e:
print("Post Error\n", e) print("Post Error\n", e)
raise raise