Should we enforce that upload files are opened in binary mode? #1538
Unanswered
tomchristie
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think we might(?) want to disallow files opened in text mode for multipart and raw content uploads...
Reason being that if opened in text mode, then we're initially decoding into text using the filesystem encoding, and then encoding back into bytes, using utf-8. The main problem here is that we'll peek the file length and use it for the
Content-Length
, but that might not then match what the number of bytes we send over the wire.The sensible thing to do is open the file in binary mode, so that the raw contents of the file actually are what's sent over the wire.
I haven't confirmed any concrete example cases of this causing an issue, but I recall seeing an issue on the "requests" repo mentioning that the (non-existent) 3.0 version should probably disallow files opened in text mode.
I guess a starting point for this would be a concrete example of a failing case?
Beta Was this translation helpful? Give feedback.
All reactions