From 8c7292035e67d634b0bbb1eef4d2f79d3d58c5b7 Mon Sep 17 00:00:00 2001 From: ochen1 <59662605+ochen1@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:07:07 -0600 Subject: Don't give up searching for accessToken in HAR file --- g4f/Provider/openai/har_file.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/g4f/Provider/openai/har_file.py b/g4f/Provider/openai/har_file.py index 8936c131..52cd8260 100644 --- a/g4f/Provider/openai/har_file.py +++ b/g4f/Provider/openai/har_file.py @@ -54,7 +54,10 @@ def readHAR(): if arkPreURL in v['request']['url']: chatArks.append(parseHAREntry(v)) elif v['request']['url'] == sessionUrl: - accessToken = json.loads(v["response"]["content"]["text"]).get("accessToken") + try: + accessToken = json.loads(v["response"]["content"]["text"]).get("accessToken") + except KeyError: + continue cookies = {c['name']: c['value'] for c in v['request']['cookies']} if not accessToken: raise NoValidHarFileError("No accessToken found in .har files") @@ -127,4 +130,4 @@ async def getArkoseAndAccessToken(proxy: str): if chatArk is None: return None, accessToken, cookies newReq = genArkReq(chatArk) - return await sendRequest(newReq, proxy), accessToken, cookies \ No newline at end of file + return await sendRequest(newReq, proxy), accessToken, cookies -- cgit v1.2.3