Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions finam_trade_api/base_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from typing import Any

import aiohttp
import httpx

from .token_manager import TokenManager

Expand Down Expand Up @@ -60,14 +60,14 @@ async def _exec_request(self, method: str, url: str, payload=None, **kwargs) ->
tuple[Any, bool]: Кортеж, содержащий JSON-ответ и статус успешности запроса (True/False).

Исключения:
aiohttp.ClientResponseError: Если статус ответа не 200 и content_type не "application/json".
httpx.HTTPError: Если статус ответа не 200 и content_type не "application/json".
"""
uri = f"{self._base_url}{url}"

async with aiohttp.ClientSession(headers=self._auth_headers) as session:
async with session.request(method, uri, json=payload, **kwargs) as response:
if response.status != 200:
if response.content_type != "application/json":
response.raise_for_status()
return await response.json(), False
return await response.json(), True
async with httpx.AsyncClient(headers=self._auth_headers, http2=True) as client:
response = await client.request(method, uri, json=payload, **kwargs)
if response.status_code != 200:
if "application/json" not in response.headers.get("content-type", ""):
response.raise_for_status()
return response.json(), False
return response.json(), True
Loading
Loading