From 561a0754d807271b5d92d013a1da5c23a2f8ae75 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Sat, 24 Dec 2022 14:23:54 +0000 Subject: [PATCH] Update FlareRequest --- pynyaata/session.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pynyaata/session.py b/pynyaata/session.py index a41592a..d1ff256 100644 --- a/pynyaata/session.py +++ b/pynyaata/session.py @@ -9,9 +9,9 @@ CLOUDPROXY_ENDPOINT = getenv("CLOUDPROXY_ENDPOINT") class FlareRequests(Session): - def request(self, method, url, params=None, **kwargs): + def request(self, method, url, params=None, data=None, **kwargs): if not CLOUDPROXY_ENDPOINT: - return super().request(method, url, params, **kwargs) + return super().request(method, url, params, data, **kwargs) sessions = post(CLOUDPROXY_ENDPOINT, json={"cmd": "sessions.list"}).json() @@ -26,14 +26,18 @@ class FlareRequests(Session): else: raise RequestException(response) + if params: + url += "&" if len(url.split("?")) > 1 else "?" + url = f"{url}{parse.urlencode(params)}" + post_data = { - "cmd": f"request.{method}", + "cmd": f"request.{method.lower()}", "session": FLARESESSION, "url": url, } - if params: - post_data["postData"] = parse.urlencode(params) + if data: + post_data["postData"] = parse.urlencode(data) try: response = post( @@ -44,12 +48,22 @@ class FlareRequests(Session): solution = response.json() if "solution" in solution: + if "content-type" in solution["solution"]["headers"]: + content_type = solution["solution"]["headers"][ + "content-type" + ].split(";") + if len(content_type) > 1: + charset = content_type[1].split("=") + if len(charset) > 1: + encoding = charset[1] + resolved = Response() - resolved.raw = BytesIO(solution["solution"]["response"].encode()) resolved.status_code = solution["solution"]["status"] resolved.headers = solution["solution"]["headers"] + resolved.raw = BytesIO(solution["solution"]["response"].encode()) resolved.url = url + resolved.encoding = encoding or None resolved.reason = solution["status"] resolved.cookies = solution["solution"]["cookies"]