Skip to content

Commit

Permalink
Merge pull request #201 from ashleigh-hopkins/media-type-fix
Browse files Browse the repository at this point in the history
Fix to always use json when sending a PUT/POST
  • Loading branch information
benleb authored Dec 18, 2023
2 parents c616ce2 + 0d2b22a commit dcb7846
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions surepy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down

0 comments on commit dcb7846

Please sign in to comment.