fix(http): pass the timeout with every request
requests ignores a timeout attribute on a Session, so open() setting one left every call without a timeout and an unresponsive gateway could hang a worker indefinitely. Each get/post/put now carries the driver's timeout. Closes #3
This commit is contained in:
1 parent
d5362fd382
commit
f7002114ae
3 files changed
+53
-3
No files matched your search
@@ -135,7 +135,6 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
"""Open a connection and authenticate with the Zyxel device."""
|
||||
self._session = requests.Session()
|
||||
self._session.verify = self.verify
|
||||
self._session.timeout = self.timeout
|
||||
self._session.trust_env = False
|
||||
|
||||
info = self._get_basic_info()
|
||||
@@ -164,6 +163,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
resp = self._session.post(
|
||||
self._url(self._LOGIN_PATH),
|
||||
json=enc_payload,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
result = crypto.decrypt_response(resp.json())
|
||||
@@ -185,6 +185,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
self._session.get(
|
||||
self._url(self._LOGOUT_PATH),
|
||||
params={"sessionKey": self._sessionkey},
|
||||
timeout=self.timeout,
|
||||
)
|
||||
except requests.RequestException:
|
||||
pass
|
||||
@@ -206,7 +207,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
if self._session is None:
|
||||
return None
|
||||
try:
|
||||
resp = self._session.get(self._url(self._BASIC_INFO_PATH))
|
||||
resp = self._session.get(self._url(self._BASIC_INFO_PATH), timeout=self.timeout)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
except (requests.RequestException, json.JSONDecodeError, TypeError):
|
||||
@@ -216,7 +217,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
if self._session is None:
|
||||
return None
|
||||
try:
|
||||
resp = self._session.get(self._url(self._RSA_KEY_PATH))
|
||||
resp = self._session.get(self._url(self._RSA_KEY_PATH), timeout=self.timeout)
|
||||
resp.raise_for_status()
|
||||
return resp.json().get("RSAPublicKey")
|
||||
except (requests.RequestException, json.JSONDecodeError, TypeError):
|
||||
@@ -233,6 +234,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
self._url(self._DAL_PATH),
|
||||
params={"oid": oid, "sessionkey": self._sessionkey},
|
||||
json=enc,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return self._crypto.decrypt_response(resp.json())
|
||||
@@ -246,6 +248,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
|
||||
resp = self._session.get(
|
||||
self._url(path),
|
||||
params={"sessionKey": self._sessionkey},
|
||||
timeout=self.timeout,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.text
|
||||
|
||||
Reference in new issue
Block a user