From e8a2d232131b15a094a859827cc9a6278b2e4494 Mon Sep 17 00:00:00 2001 From: UZQueen <157540577+HanaokaYuzu@users.noreply.github.com> Date: Fri, 29 Nov 2024 00:39:55 -0600 Subject: [PATCH] fix: replace deprecated argument httpx.AsyncClient deprecated argument `proxies` in favor of `proxy` in v0.28.0. Please use `proxy` instead. --- README.md | 2 +- src/gemini_webapi/client.py | 22 ++++++++++----------- src/gemini_webapi/types/image.py | 8 ++++---- src/gemini_webapi/utils/get_access_token.py | 8 ++++---- src/gemini_webapi/utils/rotate_1psidts.py | 8 ++++---- src/gemini_webapi/utils/upload_file.py | 8 ++++---- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4b669a5..23c5d37 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Secure_1PSIDTS = "COOKIE VALUE HERE" async def main(): # If browser-cookie3 is installed, simply use `client = GeminiClient()` - client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxies=None) + client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None) await client.init(timeout=30, auto_close=False, close_delay=300, auto_refresh=True) asyncio.run(main()) diff --git a/src/gemini_webapi/client.py b/src/gemini_webapi/client.py index f4d300d..c1a396e 100644 --- a/src/gemini_webapi/client.py +++ b/src/gemini_webapi/client.py @@ -77,8 +77,8 @@ class GeminiClient: __Secure-1PSID cookie value. secure_1psidts: `str`, optional __Secure-1PSIDTS cookie value, some google accounts don't require this value, provide only if it's in the cookie list. - proxies: `dict`, optional - Dict of proxies. + proxy: `str`, optional + Proxy URL. Raises ------ @@ -88,7 +88,7 @@ class GeminiClient: __slots__ = [ "cookies", - "proxies", + "proxy", "running", "client", "access_token", @@ -104,10 +104,10 @@ def __init__( self, secure_1psid: str | None = None, secure_1psidts: str | None = None, - proxies: dict | None = None, + proxy: str | None = None, ): self.cookies = {} - self.proxies = proxies + self.proxy = proxy self.running: bool = False self.client: AsyncClient | None = None self.access_token: str | None = None @@ -164,12 +164,12 @@ async def init( try: access_token, valid_cookies = await get_access_token( - base_cookies=self.cookies, proxies=self.proxies, verbose=verbose + base_cookies=self.cookies, proxy=self.proxy, verbose=verbose ) self.client = AsyncClient( timeout=timeout, - proxies=self.proxies, + proxy=self.proxy, follow_redirects=True, headers=Headers.GEMINI.value, cookies=valid_cookies, @@ -238,7 +238,7 @@ async def start_auto_refresh(self) -> None: while True: try: - new_1psidts = await rotate_1psidts(self.cookies, self.proxies) + new_1psidts = await rotate_1psidts(self.cookies, self.proxy) except AuthError: if task := rotate_tasks.get(self.cookies["__Secure-1PSID"]): task.cancel() @@ -313,7 +313,7 @@ async def generate_content( [ [ await upload_file( - image, self.proxies + image, self.proxy ), 1, ] @@ -377,7 +377,7 @@ async def generate_content( url=image[0][0][0], title=image[7][0], alt=image[0][4], - proxies=self.proxies, + proxy=self.proxy, ) for image in candidate[12][1] ] @@ -395,7 +395,7 @@ async def generate_content( alt=len(image[3][5]) > i and image[3][5][i] or image[3][5][0], - proxies=self.proxies, + proxy=self.proxy, cookies=self.cookies, ) for i, image in enumerate( diff --git a/src/gemini_webapi/types/image.py b/src/gemini_webapi/types/image.py index f08a793..1ce1f2f 100644 --- a/src/gemini_webapi/types/image.py +++ b/src/gemini_webapi/types/image.py @@ -20,14 +20,14 @@ class Image(BaseModel): Title of the image, by default is "[Image]". alt: `str`, optional Optional description of the image. - proxies: `dict`, optional - Dict of proxies used when saving image. + proxy: `str`, optional + Proxy used when saving image. """ url: str title: str = "[Image]" alt: str = "" - proxies: dict | None = None + proxy: str | None = None def __str__(self): return f"{self.title}({self.url}) - {self.alt}" @@ -80,7 +80,7 @@ async def save( return None async with AsyncClient( - follow_redirects=True, cookies=cookies, proxies=self.proxies + follow_redirects=True, cookies=cookies, proxy=self.proxy ) as client: response = await client.get(self.url) if response.status_code == 200: diff --git a/src/gemini_webapi/utils/get_access_token.py b/src/gemini_webapi/utils/get_access_token.py index 38a3640..ee1ced8 100644 --- a/src/gemini_webapi/utils/get_access_token.py +++ b/src/gemini_webapi/utils/get_access_token.py @@ -12,7 +12,7 @@ async def get_access_token( - base_cookies: dict, proxies: dict | None = None, verbose: bool = False + base_cookies: dict, proxy: str | None = None, verbose: bool = False ) -> tuple[str, dict]: """ Send a get request to gemini.google.com for each group of available cookies and return @@ -27,8 +27,8 @@ async def get_access_token( ---------- base_cookies : `dict` Base cookies to be used in the request. - proxies: `dict`, optional - Dict of proxies. + proxy: `str`, optional + Proxy URL. verbose: `bool`, optional If `True`, will print more infomation in logs. @@ -47,7 +47,7 @@ async def get_access_token( async def send_request(cookies: dict) -> tuple[Response | None, dict]: async with AsyncClient( - proxies=proxies, + proxy=proxy, headers=Headers.GEMINI.value, cookies=cookies, follow_redirects=True, diff --git a/src/gemini_webapi/utils/rotate_1psidts.py b/src/gemini_webapi/utils/rotate_1psidts.py index 32f9f81..0185c66 100644 --- a/src/gemini_webapi/utils/rotate_1psidts.py +++ b/src/gemini_webapi/utils/rotate_1psidts.py @@ -8,7 +8,7 @@ from ..exceptions import AuthError -async def rotate_1psidts(cookies: dict, proxies: dict | None = None) -> str: +async def rotate_1psidts(cookies: dict, proxy: str | None = None) -> str: """ Refresh the __Secure-1PSIDTS cookie and store the refreshed cookie value in cache file. @@ -16,8 +16,8 @@ async def rotate_1psidts(cookies: dict, proxies: dict | None = None) -> str: ---------- cookies : `dict` Cookies to be used in the request. - proxies: `dict`, optional - Dict of proxies. + proxy: `str`, optional + Proxy URL. Returns ------- @@ -39,7 +39,7 @@ async def rotate_1psidts(cookies: dict, proxies: dict | None = None) -> str: # Check if the cache file was modified in the last minute to avoid 429 Too Many Requests if not (path.is_file() and time.time() - os.path.getmtime(path) <= 60): - async with AsyncClient(proxies=proxies) as client: + async with AsyncClient(proxy=proxy) as client: response = await client.post( url=Endpoint.ROTATE_COOKIES.value, headers=Headers.ROTATE_COOKIES.value, diff --git a/src/gemini_webapi/utils/upload_file.py b/src/gemini_webapi/utils/upload_file.py index 5556b5e..ebfd3da 100644 --- a/src/gemini_webapi/utils/upload_file.py +++ b/src/gemini_webapi/utils/upload_file.py @@ -7,7 +7,7 @@ @validate_call -async def upload_file(file: bytes | str | Path, proxies: dict | None = None) -> str: +async def upload_file(file: bytes | str | Path, proxy: str | None = None) -> str: """ Upload a file to Google's server and return its identifier. @@ -15,8 +15,8 @@ async def upload_file(file: bytes | str | Path, proxies: dict | None = None) -> ---------- file : `bytes` | `str` | `Path` File data in bytes, or path to the file to be uploaded. - proxies: `dict`, optional - Dict of proxies. + proxy: `str`, optional + Proxy URL. Returns ------- @@ -34,7 +34,7 @@ async def upload_file(file: bytes | str | Path, proxies: dict | None = None) -> with open(file, "rb") as f: file = f.read() - async with AsyncClient(proxies=proxies) as client: + async with AsyncClient(proxy=proxy) as client: response = await client.post( url=Endpoint.UPLOAD.value, headers=Headers.UPLOAD.value,