Skip to content

Commit

Permalink
fix: BytesPayload instead of pure bytes for post/patch/put requests
Browse files Browse the repository at this point in the history
  • Loading branch information
danfimov committed Sep 18, 2023
1 parent 7bbca90 commit 6ae1462
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions ya_tracker_client/domain/client/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from abc import ABC, abstractmethod
from http import HTTPStatus
from json import dumps
from logging import getLogger
from typing import Any

from aiohttp import BytesPayload

from ya_tracker_client.domain.client.errors import (
ClientAuthError,
ClientError,
Expand Down Expand Up @@ -55,11 +58,17 @@ async def request(
payload: dict[str, Any] | None = None,
) -> bytes:
uri = f"{self._base_url}/{self._api_version}{uri}"

bytes_payload = BytesPayload(
value=bytes(dumps(payload), encoding="utf-8"),
content_type="application/json",
)

status, body = await self._make_request(
method=method,
url=uri,
params=params,
data=payload,
data=bytes_payload,
)
self._check_status(status, body)
return body
Expand All @@ -70,7 +79,7 @@ async def _make_request(
method: str,
url: str,
params: dict[str, Any] | None = None,
data: bytes | None = None,
data: bytes | BytesPayload | None = None,
) -> tuple[int, bytes]:
"""
Get raw response from via http-client.
Expand Down
4 changes: 2 additions & 2 deletions ya_tracker_client/infrastructure/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ssl import create_default_context
from typing import Any

from aiohttp import ClientSession, ClientTimeout, TCPConnector
from aiohttp import BytesPayload, ClientSession, ClientTimeout, TCPConnector
from certifi import where

from ya_tracker_client.domain.client import BaseClient
Expand Down Expand Up @@ -51,7 +51,7 @@ async def _make_request(
method: str,
url: str,
params: dict[str, Any] | None = None,
data: bytes | None = None,
data: bytes | BytesPayload | None = None,
) -> tuple[int, bytes]:
session = self._get_session()
async with session.request(method, url, params=params, data=data) as response:
Expand Down

0 comments on commit 6ae1462

Please sign in to comment.