AsyncClient does not detect length of file-like object #2265
Unanswered
rubenbaer
asked this question in
Potential Issue
Replies: 1 comment 1 reply
-
Okay - I reckon we should do that then. Yes it's a blocking operation, which we wouldn't normally want to do in an async context, but in practise making sync file accesses like that is actually perfectly okay performance-wise. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is related to issue #1490. The blocking
httpx.ClientdetectsContent-Lengthfor file like objects. But this is not implemented forhttpx.AsyncClient(seehttpx/httpx/_content.py
Line 110 in 9baf3a6
I am using
httpxto upload files with presigned URLs to a MinIO AWS S3 target. Since a blocking upload is not cancellable by Trio, I prefer to usehttpx.AsyncClient. The current workaround is to set theContent-Lengthheader explicitly. However, thepeek_filelike_lengthfunction also works in the async context and changing theencode_contentfunction accordingly should also work.Expected
Sync and async code should be similar.
Actual
Headers({'host': 'httpbin.org', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive', 'user-agent': 'python-httpx/0.23.0', 'content-length': '6'}) Headers({'host': 'httpbin.org', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive', 'user-agent': 'python-httpx/0.23.0', 'transfer-encoding': 'chunked'})Context
PUT with presigned AWS S3 URL fails as Transfer-Encoding chunked is not supported.
Beta Was this translation helpful? Give feedback.
All reactions