From dacc7a45f6ee4947045f61a4b007ef8ea6baf3f4 Mon Sep 17 00:00:00 2001 From: avk Date: Fri, 19 Nov 2021 17:44:57 +0500 Subject: [PATCH] fix request content encoding --- .github/workflows/ci.yml | 2 +- src/vektonn/async_client.py | 4 ++-- src/vektonn/client.py | 4 ++-- tests/test_client.py | 2 +- tests/test_client_async.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5c5a63..cc513d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: - master env: - VEKTONN_PYTHON_PACKAGE_VERSION: 0.5.2 + VEKTONN_PYTHON_PACKAGE_VERSION: 0.5.3 jobs: test: diff --git a/src/vektonn/async_client.py b/src/vektonn/async_client.py index 8505d2f..7382cef 100644 --- a/src/vektonn/async_client.py +++ b/src/vektonn/async_client.py @@ -11,7 +11,7 @@ class VektonnAsync: _request_headers = { 'Accept': 'application/json', - 'Content-type': 'application/json', + 'Content-Type': 'application/json; charset=utf-8', } def __init__(self, base_url: str): @@ -43,7 +43,7 @@ async def _post( query_dto: VektonnBaseModel, result_dto_type: Optional[Type[VektonnBaseModel]] = None ) -> Optional[VektonnBaseModel]: - request_content = query_dto.json() + request_content = query_dto.json().encode('utf-8') async with ClientSession() as requests: async with requests.post(url, headers=self._request_headers, data=request_content) as response: if self._is_successful(response): diff --git a/src/vektonn/client.py b/src/vektonn/client.py index 56a4c0c..799978f 100644 --- a/src/vektonn/client.py +++ b/src/vektonn/client.py @@ -12,7 +12,7 @@ class Vektonn: _request_headers = { 'Accept': 'application/json', - 'Content-type': 'application/json', + 'Content-Type': 'application/json; charset=utf-8', } def __init__(self, base_url: str): @@ -44,7 +44,7 @@ def _post( query_dto: VektonnBaseModel, result_dto_type: Optional[Type[VektonnBaseModel]] = None ) -> Optional[VektonnBaseModel]: - request_content = query_dto.json() + request_content = query_dto.json().encode('utf-8') response = requests.post(url, headers=self._request_headers, data=request_content) if self._is_successful(response): diff --git a/tests/test_client.py b/tests/test_client.py index 597d92c..0f24005 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -44,7 +44,7 @@ def test_upload__success(vektonn_client: Vektonn): attributes=[ AttributeDto(key='Id', value=AttributeValueDto(int64=42)), AttributeDto(key='SplitId', value=AttributeValueDto(bool=True)), - AttributeDto(key='Payload', value=AttributeValueDto(string='la-la-la')), + AttributeDto(key='Payload', value=AttributeValueDto(string='la-la-la and some unicode chars Ὀδύσσεια 曳航')), ], is_deleted=True, ) diff --git a/tests/test_client_async.py b/tests/test_client_async.py index cd1c02a..f5d640c 100644 --- a/tests/test_client_async.py +++ b/tests/test_client_async.py @@ -44,7 +44,7 @@ async def test_upload__success(vektonn_client_async: VektonnAsync): attributes=[ AttributeDto(key='Id', value=AttributeValueDto(int64=42)), AttributeDto(key='SplitId', value=AttributeValueDto(bool=True)), - AttributeDto(key='Payload', value=AttributeValueDto(string='la-la-la')), + AttributeDto(key='Payload', value=AttributeValueDto(string='la-la-la and some unicode chars Ὀδύσσεια 曳航')), ], is_deleted=True, )