RuntimeError when AsyncClient.put has binary request body. #2961
Answered
by
ThermodynamicBeta
lee-cq
asked this question in
Potential Issue
|
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.
|
Answered by
ThermodynamicBeta
May 29, 2025
Replies: 5 comments
|
I do more tests.
|
0 replies
|
Any solution to this? |
0 replies
|
Ah, from the docs: https://www.python-httpx.org/async/ |
0 replies
Answer selected by
lee-cq
|
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) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

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