RuntimeError when AsyncClient.put has binary request body. #2961
-
|
When I wish to upload data using AsyncClient.put, it triggers an error telling me this is a synchronous request. Demo import asyncio
from httpx import AsyncClient
client = AsyncClient(base_url="https://google.com", timeout=10)
async def run():
a = await client.put(
"/api/fs/put",
content=open(__file__, "rb")
)
print(a.json())
asyncio.run(run())Error Info: Maybe this is a BUG.
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
|
I did some debugging: |
Beta Was this translation helpful? Give feedback.
-
|
I do more tests.
|
Beta Was this translation helpful? Give feedback.
-
|
Any solution to this? |
Beta Was this translation helpful? Give feedback.
-
|
Ah, from the docs: https://www.python-httpx.org/async/ |
Beta Was this translation helpful? Give feedback.
-
|
After using aiofiles.open to replace the raw open function, there's no error. But I don't know how it‘s performs. Here's the code: import aiofiles
async with aiofiles.open("xxx.file", "rb") as f:
async with httpx.AsyncClinet() as client:
resp = await client.request("PUT", "url", data=f) |
Beta Was this translation helpful? Give feedback.

Ah, from the docs: https://www.python-httpx.org/async/