@@ -395,7 +395,7 @@ async def a_raw_post(self, path: str, data: dict, **kwargs: dict) -> AsyncRespon
395395 method = "POST" ,
396396 url = urljoin (self .base_url , path ),
397397 params = self ._filter_query_params (kwargs ),
398- data = data ,
398+ ** self . _prepare_httpx_request_content ( data ) ,
399399 headers = self .headers ,
400400 timeout = self .timeout ,
401401 )
@@ -421,7 +421,7 @@ async def a_raw_put(self, path: str, data: dict, **kwargs: dict) -> AsyncRespons
421421 return await self .async_s .put (
422422 urljoin (self .base_url , path ),
423423 params = self ._filter_query_params (kwargs ),
424- data = data ,
424+ ** self . _prepare_httpx_request_content ( data ) ,
425425 headers = self .headers ,
426426 timeout = self .timeout ,
427427 )
@@ -452,7 +452,7 @@ async def a_raw_delete(
452452 return await self .async_s .request (
453453 method = "DELETE" ,
454454 url = urljoin (self .base_url , path ),
455- data = data or {},
455+ ** self . _prepare_httpx_request_content ( data or {}) ,
456456 params = self ._filter_query_params (kwargs ),
457457 headers = self .headers ,
458458 timeout = self .timeout ,
@@ -461,6 +461,23 @@ async def a_raw_delete(
461461 msg = "Can't connect to server"
462462 raise KeycloakConnectionError (msg ) from e
463463
464+ @staticmethod
465+ def _prepare_httpx_request_content (data : dict | str | None ) -> dict :
466+ """
467+ Create the correct request content kwarg to `httpx.AsyncClient.request()`.
468+
469+ See https://www.python-httpx.org/compatibility/#request-content
470+
471+ :param data: the request content
472+ :type data: dict | str | None
473+ :returns: A dict mapping the correct kwarg to the request content
474+ :rtype: dict
475+ """
476+ if isinstance (data , str ):
477+ # Note: this could also accept bytes, Iterable[bytes], or AsyncIterable[bytes]
478+ return {"content" : data }
479+ return {"data" : data }
480+
464481 @staticmethod
465482 def _filter_query_params (query_params : dict ) -> dict :
466483 """
0 commit comments