Skip to content

Commit 8d9a7b1

Browse files
authored
🐛 Fix: Add wrapper to prep data for JSON encoding (#22)
closes #21
1 parent bc1eb96 commit 8d9a7b1

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

githubkit/core.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
import httpx
20+
from pydantic.json import pydantic_encoder
2021

2122
from .response import Response
2223
from .config import Config, get_config
@@ -237,7 +238,7 @@ def _request(
237238
content=content,
238239
data=data,
239240
files=files,
240-
json=json,
241+
json=self._convert(json),
241242
headers=headers,
242243
cookies=cookies,
243244
)
@@ -269,7 +270,7 @@ async def _arequest(
269270
content=content,
270271
data=data,
271272
files=files,
272-
json=json,
273+
json=self._convert(json),
273274
headers=headers,
274275
cookies=cookies,
275276
)
@@ -298,6 +299,18 @@ def _check(
298299
raise RequestFailed(rep)
299300
return Response(response, response_model)
300301

302+
def _convert(self, obj: Any) -> Any:
303+
if isinstance(obj, dict):
304+
return {k: self._convert(v) for k, v in obj.items()}
305+
306+
if isinstance(obj, (list, tuple)):
307+
return [self._convert(item) for item in obj]
308+
309+
if obj is None or isinstance(obj, (int, float, str, bool)):
310+
return obj
311+
312+
return pydantic_encoder(obj)
313+
301314
# sync request and check
302315
def request(
303316
self,

0 commit comments

Comments
 (0)