This commit is contained in:
parent
eb23799cd7
commit
4dee2ea36e
@ -8,8 +8,22 @@ class FlareRequests(Session):
|
|||||||
if not CLOUDPROXY_ENDPOINT:
|
if not CLOUDPROXY_ENDPOINT:
|
||||||
return super().request(method, url, params, timeout=timeout, **kwargs)
|
return super().request(method, url, params, timeout=timeout, **kwargs)
|
||||||
|
|
||||||
|
sessions = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.list"}).json()
|
||||||
|
|
||||||
|
if "sessions" in sessions and len(sessions["sessions"]) > 0:
|
||||||
|
FLARESESSION = sessions["sessions"][0]
|
||||||
|
else:
|
||||||
|
response = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.create"})
|
||||||
|
session = response.json()
|
||||||
|
|
||||||
|
if "session" in session:
|
||||||
|
FLARESESSION = session["session"]
|
||||||
|
else:
|
||||||
|
raise RequestException(response)
|
||||||
|
|
||||||
post_data = {
|
post_data = {
|
||||||
"cmd": f"request.{method.lower()}",
|
"cmd": f"request.{method.lower()}",
|
||||||
|
"session": FLARESESSION,
|
||||||
"url": url,
|
"url": url,
|
||||||
"maxTimeout": timeout * 1000,
|
"maxTimeout": timeout * 1000,
|
||||||
}
|
}
|
||||||
@ -17,23 +31,31 @@ class FlareRequests(Session):
|
|||||||
if params:
|
if params:
|
||||||
post_data["postData"] = parse.urlencode(params)
|
post_data["postData"] = parse.urlencode(params)
|
||||||
|
|
||||||
response = post(
|
try:
|
||||||
CLOUDPROXY_ENDPOINT,
|
response = post(
|
||||||
json=post_data,
|
CLOUDPROXY_ENDPOINT,
|
||||||
)
|
json=post_data,
|
||||||
|
)
|
||||||
|
|
||||||
solution = response.json()
|
solution = response.json()
|
||||||
|
|
||||||
if "solution" in solution:
|
if "solution" in solution:
|
||||||
resolved = Response()
|
resolved = Response()
|
||||||
|
|
||||||
resolved.raw = solution["solution"]["response"]
|
resolved.raw = solution["solution"]["response"]
|
||||||
resolved.status_code = solution["solution"]["status"]
|
resolved.status_code = solution["solution"]["status"]
|
||||||
resolved.headers = solution["solution"]["headers"]
|
resolved.headers = solution["solution"]["headers"]
|
||||||
resolved.url = url
|
resolved.url = url
|
||||||
resolved.reason = solution["status"]
|
resolved.reason = solution["status"]
|
||||||
resolved.cookies = solution["solution"]["cookies"]
|
resolved.cookies = solution["solution"]["cookies"]
|
||||||
|
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
raise RequestException(response)
|
raise RequestException(response)
|
||||||
|
except RequestException:
|
||||||
|
session = post(
|
||||||
|
CLOUDPROXY_ENDPOINT,
|
||||||
|
json={"cmd": "sessions.destroy", "session": FLARESESSION},
|
||||||
|
)
|
||||||
|
|
||||||
|
raise RequestException(solution)
|
||||||
|
Reference in New Issue
Block a user