This commit is contained in:
parent
edd06e5bbb
commit
e1e805a91b
@ -19,74 +19,45 @@ class FlareRequests(requests.Session):
|
|||||||
if not CLOUDPROXY_ENDPOINT:
|
if not CLOUDPROXY_ENDPOINT:
|
||||||
return super().request(method, url, params, data, **kwargs)
|
return super().request(method, url, params, data, **kwargs)
|
||||||
|
|
||||||
sessions = requests.post(
|
|
||||||
CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.list"}
|
|
||||||
).json()
|
|
||||||
|
|
||||||
if "sessions" in sessions and len(sessions["sessions"]) > 0:
|
|
||||||
FLARESESSION = sessions["sessions"][0]
|
|
||||||
else:
|
|
||||||
response = requests.post(
|
|
||||||
CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.create"}
|
|
||||||
)
|
|
||||||
session = response.json()
|
|
||||||
|
|
||||||
if "session" in session:
|
|
||||||
FLARESESSION = session["session"]
|
|
||||||
else:
|
|
||||||
raise requests.RequestException(response)
|
|
||||||
|
|
||||||
if params:
|
if params:
|
||||||
url += "&" if len(url.split("?")) > 1 else "?"
|
url += "&" if len(url.split("?")) > 1 else "?"
|
||||||
url = f"{url}{urllib.parse.urlencode(params)}"
|
url = f"{url}{urllib.parse.urlencode(params)}"
|
||||||
|
|
||||||
post_data = {
|
post_data = {
|
||||||
"cmd": f"request.{method.lower()}",
|
"cmd": f"request.{method.lower()}",
|
||||||
"session": FLARESESSION,
|
|
||||||
"url": url,
|
"url": url,
|
||||||
}
|
}
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
post_data["postData"] = urllib.parse.urlencode(data)
|
post_data["postData"] = urllib.parse.urlencode(data)
|
||||||
|
|
||||||
try:
|
response = requests.post(
|
||||||
response = requests.post(
|
CLOUDPROXY_ENDPOINT,
|
||||||
CLOUDPROXY_ENDPOINT,
|
json=post_data,
|
||||||
json=post_data,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
solution = response.json()
|
content = response.json()
|
||||||
|
|
||||||
if "solution" in solution:
|
if "solution" in content:
|
||||||
if "content-type" in solution["solution"]["headers"]:
|
solution = content["solution"]
|
||||||
content_type = solution["solution"]["headers"][
|
if "content-type" in solution["headers"]:
|
||||||
"content-type"
|
content_type = solution["headers"]["content-type"].split(";")
|
||||||
].split(";")
|
if len(content_type) > 1:
|
||||||
if len(content_type) > 1:
|
charset = content_type[1].split("=")
|
||||||
charset = content_type[1].split("=")
|
if len(charset) > 1:
|
||||||
if len(charset) > 1:
|
encoding = charset[1]
|
||||||
encoding = charset[1]
|
|
||||||
|
|
||||||
resolved = requests.Response()
|
resolved = requests.Response()
|
||||||
|
|
||||||
resolved.status_code = solution["solution"]["status"]
|
resolved.status_code = solution["status"]
|
||||||
resolved.headers = solution["solution"]["headers"]
|
resolved.headers = solution["headers"]
|
||||||
resolved.raw = io.BytesIO(solution["solution"]["response"].encode())
|
resolved.raw = io.BytesIO(solution["response"].encode())
|
||||||
resolved.url = url
|
resolved.url = url
|
||||||
resolved.encoding = encoding or None
|
resolved.encoding = encoding or None
|
||||||
resolved.reason = solution["status"]
|
resolved.reason = content["status"]
|
||||||
resolved.cookies = solution["solution"]["cookies"]
|
resolved.cookies = solution["cookies"]
|
||||||
|
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
raise requests.RequestException(response)
|
|
||||||
except requests.RequestException:
|
|
||||||
session = requests.post(
|
|
||||||
CLOUDPROXY_ENDPOINT,
|
|
||||||
json={"cmd": "sessions.destroy", "session": FLARESESSION},
|
|
||||||
)
|
|
||||||
|
|
||||||
raise requests.RequestException(solution)
|
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
Loading…
Reference in New Issue
Block a user