Skip to content

Commit

Permalink
fix: replace deprecated argument
Browse files Browse the repository at this point in the history
httpx.AsyncClient deprecated argument `proxies` in favor of `proxy` in v0.28.0. Please use `proxy` instead.
  • Loading branch information
HanaokaYuzu committed Nov 29, 2024
1 parent 9b0911e commit e8a2d23
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
22 changes: 11 additions & 11 deletions src/gemini_webapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand All @@ -88,7 +88,7 @@ class GeminiClient:

__slots__ = [
"cookies",
"proxies",
"proxy",
"running",
"client",
"access_token",
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -313,7 +313,7 @@ async def generate_content(
[
[
await upload_file(
image, self.proxies
image, self.proxy
),
1,
]
Expand Down Expand Up @@ -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]
]
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/gemini_webapi/types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/gemini_webapi/utils/get_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/gemini_webapi/utils/rotate_1psidts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
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.
Parameters
----------
cookies : `dict`
Cookies to be used in the request.
proxies: `dict`, optional
Dict of proxies.
proxy: `str`, optional
Proxy URL.
Returns
-------
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/gemini_webapi/utils/upload_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@


@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.
Parameters
----------
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
-------
Expand All @@ -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,
Expand Down

0 comments on commit e8a2d23

Please sign in to comment.