mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-28 11:07:24 +03:00
Add --cookie-browsers argument to cli
This commit is contained in:
parent
1fe59623b2
commit
275404373f
@ -40,6 +40,7 @@ try:
|
||||
has_browser_cookie3 = True
|
||||
except ImportError:
|
||||
has_browser_cookie3 = False
|
||||
browsers = []
|
||||
|
||||
from .typing import Dict, Cookies
|
||||
from .errors import MissingRequirementsError
|
||||
|
@ -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
|
||||
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
|
||||
)
|
Loading…
Reference in New Issue
Block a user