From 0d2b22a0bc39da1ec207721a451b24eb356bf307 Mon Sep 17 00:00:00 2001 From: Ash Hopkins Date: Wed, 13 Dec 2023 17:23:25 +0000 Subject: [PATCH] Fix to always use json when sending a PUT/POST --- surepy/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/surepy/client.py b/surepy/client.py index eff2ad3..5d1bde5 100644 --- a/surepy/client.py +++ b/surepy/client.py @@ -166,7 +166,7 @@ async def get_token(self) -> str | None: try: raw_response: aiohttp.ClientResponse = await session.post( - url=AUTH_RESOURCE, data=authentication_data, headers=self._generate_headers() + url=AUTH_RESOURCE, json=authentication_data, headers=self._generate_headers() ) if raw_response.status == HTTPStatus.OK: @@ -216,6 +216,9 @@ async def call( # if data: # logger.debug("🐾 with data: %s", data) + if json and not data: + data = json + if not self._auth_token: self._auth_token = await self.get_token() @@ -237,7 +240,7 @@ async def call( await session.options(resource, headers=headers) response: aiohttp.ClientResponse = await session.request( - method, resource, headers=headers, data=data, json=json + method, resource, headers=headers, json=data ) if response.status == HTTPStatus.OK or response.status == HTTPStatus.CREATED: