From 46c44777f7c61d0aad1abb5ec63bb0f88584893b Mon Sep 17 00:00:00 2001 From: p1c2u Date: Wed, 20 Sep 2023 19:06:20 +0000 Subject: [PATCH] aiohttp response binary format support --- openapi_core/contrib/aiohttp/responses.py | 5 ++++- tests/integration/contrib/aiohttp/test_aiohttp_project.py | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/openapi_core/contrib/aiohttp/responses.py b/openapi_core/contrib/aiohttp/responses.py index 40771e2f..a7baf851 100644 --- a/openapi_core/contrib/aiohttp/responses.py +++ b/openapi_core/contrib/aiohttp/responses.py @@ -17,7 +17,10 @@ def data(self) -> str: if self.response.body is None: return "" if isinstance(self.response.body, bytes): - return self.response.body.decode("utf-8") + try: + return self.response.body.decode("utf-8") + except UnicodeDecodeError: + return self.response.body assert isinstance(self.response.body, str) return self.response.body diff --git a/tests/integration/contrib/aiohttp/test_aiohttp_project.py b/tests/integration/contrib/aiohttp/test_aiohttp_project.py index f7abfee3..9b1aee14 100644 --- a/tests/integration/contrib/aiohttp/test_aiohttp_project.py +++ b/tests/integration/contrib/aiohttp/test_aiohttp_project.py @@ -38,10 +38,6 @@ def api_key_encoded(self): class TestPetPhotoView(BaseTestPetstore): - @pytest.mark.xfail( - reason="response binary format not supported", - strict=True, - ) async def test_get_valid(self, client, data_gif): headers = { "Authorization": "Basic testuser",