-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File upload with httpx from utf-8 str content (not encoded) leads to h11._util.LocalProtocolError: Too much data for declared Content-Length #2381
Comments
Probably about uvicorn.run(app, host="0.0.0.0", port=20000, log_level='trace', http="httptools") |
Does not help. I forget to mention exception is on client side. |
Can you try setting a content-type? await cli.put('/upload', files=[('file', ('sample.txt', 'Й', 'text/plain'))] If it doesn't work, please check the content-length of the outgoing request and incoming request using a debugger. |
It doesn't work.
Sorry, I don't get how to do it, instead i captured outgoing packets from client using Wireshark, here them are. Good, sending 'Q'.
Bad, sending 'Й'.
|
This seams to be a problem with how HTTPx calculates the content-length. @AntonOvsyannikov Try using the Requests module instead and see if you can replicate the Problem. It happens with 'HTTPx' but not when I use 'requests': import requests
def main():
base_url='http://127.0.0.1:20000'
# requests.put(f'{base_url}/upload', files=[('file', ('sample.txt', 'Q'))]) # ok
# requests.put(f'{base_url}/upload', files=[('file', ('sample.txt', 'Й'.encode()))]) # ok
requests.put(f'{base_url}/upload', files=[('file', ('sample.txt', 'Й'))]) # ok
if __name__ == "__main__":
main() |
I suspect this was changed recently, the content part has to be bytes now it seems.
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
First check
Example
Server
Client
Description
Not sure it's about FastAPI or httpx, but suppose it should be useful here anyway.
Upload file with httpx.put (using
files=
) to FastAPI endpoint from not encoded utf-8 string content leads to exception, but should not,str
is acceptable content type for httpx due toFileContent = Union[IO[str], IO[bytes], str, bytes]
Environment
The text was updated successfully, but these errors were encountered: