summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/openai/har_file.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 15:15:55 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 15:15:55 +0200
commita26421bcd8b8580650fa05b3fb4f8fdfa0ef9921 (patch)
treeb1c7ff275c54682e29f89f07638b8fdd1743e0e1 /g4f/Provider/openai/har_file.py
parentAdd MissingRequirementsError to You (diff)
downloadgpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.gz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.bz2
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.lz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.xz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.zst
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.zip
Diffstat (limited to 'g4f/Provider/openai/har_file.py')
-rw-r--r--g4f/Provider/openai/har_file.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py
index 52cd8260..c1b3b9f1 100644
--- a/g4f/Provider/openai/har_file.py
+++ b/g4f/Provider/openai/har_file.py
@@ -59,17 +59,21 @@ def readHAR():
except KeyError:
continue
cookies = {c['name']: c['value'] for c in v['request']['cookies']}
+ headers = get_headers(v)
if not accessToken:
raise NoValidHarFileError("No accessToken found in .har files")
if not chatArks:
- return None, accessToken, cookies
- return chatArks.pop(), accessToken, cookies
+ return None, accessToken, cookies, headers
+ return chatArks.pop(), accessToken, cookies, headers
+
+def get_headers(entry) -> dict:
+ return {h['name'].lower(): h['value'] for h in entry['request']['headers'] if h['name'].lower() not in ['content-length', 'cookie'] and not h['name'].startswith(':')}
def parseHAREntry(entry) -> arkReq:
tmpArk = arkReq(
arkURL=entry['request']['url'],
arkBx="",
- arkHeader={h['name'].lower(): h['value'] for h in entry['request']['headers'] if h['name'].lower() not in ['content-length', 'cookie'] and not h['name'].startswith(':')},
+ arkHeader=get_headers(entry),
arkBody={p['name']: unquote(p['value']) for p in entry['request']['postData']['params'] if p['name'] not in ['rnd']},
arkCookies={c['name']: c['value'] for c in entry['request']['cookies']},
userAgent=""
@@ -123,11 +127,11 @@ def getN() -> str:
timestamp = str(int(time.time()))
return base64.b64encode(timestamp.encode()).decode()
-async def getArkoseAndAccessToken(proxy: str):
+async def getArkoseAndAccessToken(proxy: str) -> tuple[str, str, dict, dict]:
global chatArk, accessToken, cookies
if chatArk is None or accessToken is None:
- chatArk, accessToken, cookies = readHAR()
+ chatArk, accessToken, cookies, headers = readHAR()
if chatArk is None:
- return None, accessToken, cookies
+ return None, accessToken, cookies, headers
newReq = genArkReq(chatArk)
- return await sendRequest(newReq, proxy), accessToken, cookies
+ return await sendRequest(newReq, proxy), accessToken, cookies, headers