diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-24 00:46:35 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-24 00:46:35 +0100 |
commit | 69ef224f92fcec3335a857305191678b886651e1 (patch) | |
tree | e2eb38fc678c68fa75b06631880172d164a9c7e7 /g4f/Provider/helper.py | |
parent | Add aiohttp_socks support (diff) | |
download | gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.gz gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.bz2 gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.lz gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.xz gpt4free-69ef224f92fcec3335a857305191678b886651e1.tar.zst gpt4free-69ef224f92fcec3335a857305191678b886651e1.zip |
Diffstat (limited to 'g4f/Provider/helper.py')
-rw-r--r-- | g4f/Provider/helper.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/g4f/Provider/helper.py b/g4f/Provider/helper.py index fce1ee6f..cf204e39 100644 --- a/g4f/Provider/helper.py +++ b/g4f/Provider/helper.py @@ -6,13 +6,15 @@ import random import secrets import string from asyncio import AbstractEventLoop, BaseEventLoop +from aiohttp import BaseConnector from platformdirs import user_config_dir from browser_cookie3 import ( chrome, chromium, opera, opera_gx, brave, edge, vivaldi, firefox, _LinuxPasswordManager, BrowserCookieError ) -from ..typing import Dict, Messages +from ..typing import Dict, Messages, Optional +from ..errors import AiohttpSocksError from .. import debug # Global variable to store cookies @@ -147,4 +149,13 @@ def get_random_hex() -> str: Returns: str: A random hexadecimal string of 32 characters (16 bytes). """ - return secrets.token_hex(16).zfill(32)
\ No newline at end of file + return secrets.token_hex(16).zfill(32) + +def get_connector(connector: BaseConnector = None, proxy: str = None) -> Optional[BaseConnector]: + if proxy and not connector: + try: + from aiohttp_socks import ProxyConnector + connector = ProxyConnector.from_url(proxy) + except ImportError: + raise AiohttpSocksError('Install "aiohttp_socks" package for proxy support') + return connector
\ No newline at end of file |