summaryrefslogtreecommitdiffstats
path: root/g4f/cookies.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-02-09 18:51:27 +0100
committerGitHub <noreply@github.com>2024-02-09 18:51:27 +0100
commit6c7c293fd16b970d857c888b5108334f00b27a19 (patch)
tree3deecb18f982e133cb3b0337ffb0bdcbb607a212 /g4f/cookies.py
parentUpdate OpenaiChat.py (diff)
parentUpdate Gemini.py (diff)
downloadgpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar.gz
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar.bz2
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar.lz
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar.xz
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.tar.zst
gpt4free-6c7c293fd16b970d857c888b5108334f00b27a19.zip
Diffstat (limited to 'g4f/cookies.py')
-rw-r--r--g4f/cookies.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py
index b5c869e7..af0e6192 100644
--- a/g4f/cookies.py
+++ b/g4f/cookies.py
@@ -27,7 +27,7 @@ _cookies: Dict[str, Cookies] = {}
if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":
_LinuxPasswordManager.get_password = lambda a, b: b"secret"
-def get_cookies(domain_name: str = '', raise_requirements_error: bool = True) -> Dict[str, str]:
+def get_cookies(domain_name: str = '', raise_requirements_error: bool = True, single_browser: bool = False) -> Dict[str, str]:
"""
Load cookies for a given domain from all supported browsers and cache the results.
@@ -40,7 +40,7 @@ def get_cookies(domain_name: str = '', raise_requirements_error: bool = True) ->
if domain_name in _cookies:
return _cookies[domain_name]
- cookies = load_cookies_from_browsers(domain_name, raise_requirements_error)
+ cookies = load_cookies_from_browsers(domain_name, raise_requirements_error, single_browser)
_cookies[domain_name] = cookies
return cookies
@@ -50,7 +50,7 @@ def set_cookies(domain_name: str, cookies: Cookies = None) -> None:
elif domain_name in _cookies:
_cookies.pop(domain_name)
-def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool = True) -> Cookies:
+def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool = True, single_browser: bool = False) -> Cookies:
"""
Helper function to load cookies from various browsers.
@@ -73,6 +73,8 @@ def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool
for cookie in cookie_jar:
if cookie.name not in cookies:
cookies[cookie.name] = cookie.value
+ if single_browser and len(cookie_jar):
+ break
except BrowserCookieError:
pass
except Exception as e: