Skip to content

Commit 28bc530

Browse files
committed
minor fixes
1 parent 0b8b1ef commit 28bc530

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

pyaterochka_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .enums import PurchaseMode, Sorting
22
from .manager import PyaterochkaAPI
33

4-
__version__ = "0.2.2"
4+
__version__ = "0.2.3"
55
__all__ = ["PyaterochkaAPI", "PurchaseMode", "Sorting"]

pyaterochka_api/endpoints/general.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from io import BytesIO
44
from typing import TYPE_CHECKING
55

6+
from human_requests.abstraction import Proxy
67
from aiohttp_retry import ExponentialRetry, RetryClient
78

89
if TYPE_CHECKING:
@@ -23,12 +24,14 @@ async def download_image(
2324
self, url: str, retry_attempts: int = 3, timeout: float = 10
2425
) -> BytesIO:
2526
"""Скачать изображение по URL."""
27+
proxy = Proxy(self.proxy).as_str() if self._parent.proxy else None
28+
2629
retry_options = ExponentialRetry(
2730
attempts=retry_attempts, start_timeout=3.0, max_timeout=timeout
2831
)
2932

3033
async with RetryClient(retry_options=retry_options) as retry_client:
31-
async with retry_client.get(url, raise_for_status=True) as resp:
34+
async with retry_client.get(url, raise_for_status=True, proxy=proxy) as resp:
3235
body = await resp.read()
3336
file = BytesIO(body)
3437
file.name = url.split("/")[-1]

pyaterochka_api/manager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def _warmup(self) -> None:
139139
result[header].update(values) # добавляем значения, set уберёт дубли
140140

141141
# Преобразуем set обратно в list
142-
self.unstandard_headers = {k: list(v) for k, v in result.items()}
142+
self.unstandard_headers = {k: list(v)[0] for k, v in result.items()}
143143

144144
async def __aexit__(self, *exc):
145145
"""Выход из контекстного менеджера с закрытием сессии."""
@@ -180,9 +180,7 @@ async def _request(
180180
credentials="include" if credentials else "omit",
181181
timeout_ms=self.timeout_ms,
182182
referrer=self.MAIN_SITE_URL,
183-
headers={"Accept": "application/json, text/plain, */*"}.update(
184-
self.unstandard_headers if add_unstandard_headers else {}
185-
),
183+
headers={"Accept": "application/json, text/plain, */*"} | (self.unstandard_headers if add_unstandard_headers else {}),
186184
)
187185

188186
return resp

0 commit comments

Comments
 (0)