diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 20:53:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 20:53:11 +0100 |
commit | de4f374c5d01216cf62ba3594cff3762a1fd8159 (patch) | |
tree | 7dd083571e2396a627dfd468f21af8402cc39f2d /g4f/requests/__init__.py | |
parent | Merge pull request #2382 from hlohaus/info (diff) | |
parent | Add --cookie-browsers argument to cli (diff) | |
download | gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.gz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.bz2 gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.lz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.xz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.zst gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.zip |
Diffstat (limited to 'g4f/requests/__init__.py')
-rw-r--r-- | g4f/requests/__init__.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/g4f/requests/__init__.py b/g4f/requests/__init__.py index 89e0b4ea..2e576d19 100644 --- a/g4f/requests/__init__.py +++ b/g4f/requests/__init__.py @@ -20,9 +20,15 @@ except ImportError: try: import nodriver from nodriver.cdp.network import CookieParam + from nodriver import Browser has_nodriver = True except ImportError: has_nodriver = False +try: + from platformdirs import user_config_dir + has_platformdirs = True +except ImportError: + has_platformdirs = False from .. import debug from .raise_for_status import raise_for_status @@ -165,4 +171,15 @@ def merge_cookies(cookies: Iterator[Morsel], response: Response) -> Cookies: if cookies is None: cookies = {} for cookie in response.cookies.jar: - cookies[cookie.name] = cookie.value
\ No newline at end of file + cookies[cookie.name] = cookie.value + +async def get_nodriver(proxy: str = None, **kwargs)-> Browser: + if not has_nodriver: + raise MissingRequirementsError('Install "nodriver" package | pip install -U nodriver') + user_data_dir = user_config_dir("g4f-nodriver") if has_platformdirs else None + debug.log(f"Copilot: Open nodriver with user_dir: {user_data_dir}") + return await nodriver.start( + user_data_dir=user_data_dir, + browser_args=None if proxy is None else [f"--proxy-server={proxy}"], + **kwargs + )
\ No newline at end of file |