summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/you/har_file.py
diff options
context:
space:
mode:
authorabc <98614666+xtekky@users.noreply.github.com>2024-05-15 00:45:13 +0200
committerabc <98614666+xtekky@users.noreply.github.com>2024-05-15 00:45:13 +0200
commit1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8 (patch)
treeaabd2aa2013c7526c5e4de0a9dc2e05da81a5a4c /g4f/Provider/you/har_file.py
parent. (diff)
downloadgpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar.gz
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar.bz2
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar.lz
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar.xz
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.tar.zst
gpt4free-1399758a4e000b0fe1cd3d9e86d1a4807d9e41e8.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/you/har_file.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/g4f/Provider/you/har_file.py b/g4f/Provider/you/har_file.py
index 8089d686..cfdca12f 100644
--- a/g4f/Provider/you/har_file.py
+++ b/g4f/Provider/you/har_file.py
@@ -4,11 +4,14 @@ import json
import os
import os.path
import random
+import logging
from ...requests import StreamSession, raise_for_status
from ...errors import MissingRequirementsError
from ... import debug
+logging.basicConfig(level=logging.ERROR)
+
class NoValidHarFileError(Exception):
...
@@ -62,10 +65,16 @@ def parseHAREntry(entry) -> arkReq:
return tmpArk
async def sendRequest(tmpArk: arkReq, proxy: str = None):
- async with StreamSession(headers=tmpArk.arkHeaders, cookies=tmpArk.arkCookies, proxy=proxy) as session:
- async with session.post(tmpArk.arkURL, data=tmpArk.arkBody) as response:
- await raise_for_status(response)
- return await response.text()
+ try:
+ async with StreamSession(headers=tmpArk.arkHeaders, cookies=tmpArk.arkCookies, proxy=proxy) as session:
+ async with session.post(tmpArk.arkURL, data=tmpArk.arkBody) as response:
+ await raise_for_status(response)
+ return await response.text()
+ except RuntimeError as e:
+ if str(e) == "Event loop is closed":
+ print("Event loop is closed error occurred in sendRequest.")
+ else:
+ raise
async def create_telemetry_id(proxy: str = None):
global chatArks
@@ -78,9 +87,9 @@ async def get_telemetry_ids(proxy: str = None) -> list:
return [await create_telemetry_id(proxy)]
except NoValidHarFileError as e:
if debug.logging:
- print(e)
+ logging.error(e)
if debug.logging:
- print('Getting telemetry_id for you.com with nodriver')
+ logging.error('Getting telemetry_id for you.com with nodriver')
try:
from nodriver import start
except ImportError:
@@ -100,6 +109,15 @@ async def get_telemetry_ids(proxy: str = None) -> list:
)
return [await get_telemetry_id()]
+
finally:
- if page is not None:
- await page.close() \ No newline at end of file
+ try:
+ if page is not None:
+ await page.close()
+
+ if browser is not None:
+ await browser.close()
+
+ except Exception as e:
+ if debug.logging:
+ logging.error(e)