Add timeout on FlareRequest
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michel Roux 2022-12-21 15:14:43 +00:00
parent beead16617
commit b4a8f264e1

View File

@ -1,12 +1,12 @@
from urllib import parse
from requests import RequestException, Session, post
from .config import CLOUDPROXY_ENDPOINT
from .config import CLOUDPROXY_ENDPOINT, REQUESTS_TIMEOUT
class FlareRequests(Session):
def request(self, method, url, params, **kwargs):
def request(self, method, url, params, timeout=REQUESTS_TIMEOUT, **kwargs):
if not CLOUDPROXY_ENDPOINT:
return super().request(method, url, params, **kwargs)
return super().request(method, url, params, timeout=timeout, **kwargs)
sessions = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.list"}).json()
@ -29,6 +29,7 @@ class FlareRequests(Session):
"session": FLARESESSION,
"url": url,
"postData": parse.urlencode(params),
"maxTimeout": timeout,
},
)
solution = response.json()
@ -43,7 +44,8 @@ class FlareRequests(Session):
raise RequestException(response)
except RequestException:
session = post(
CLOUDPROXY_ENDPOINT, {"cmd": "sessions.destroy", "session": FLARESESSION}
CLOUDPROXY_ENDPOINT,
{"cmd": "sessions.destroy", "session": FLARESESSION},
)
raise RequestException(solution)