Skip to content
Myr

More robust check for upload files in binary mode (#2630)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Fix check for binary mode * Change order of type checks ---------

authored by Leon Kuchenbecker · committed by GitHub · parent 26dc392 · Browse files · 1 file+4 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

1 file+4 added−4 removed

  • other:+4 added−4 removed

1 file+4 added−4 removed

modified:httpx/_multipart.py+4 added-4 removed
120 unmodified lines
121 # provided in the 3rd tuple element if it is also included in the headers122 # requests does the opposite (it overwrites the header with the 3rd tuple element)123 headers["Content-Type"] = content_type124125 if "b" not in getattr(fileobj, "mode", "b"):126 raise TypeError(127 "Multipart file uploads must be opened in binary mode, not text mode."128 )125 if isinstance(fileobj, io.StringIO):126 raise TypeError(127 "Multipart file uploads require 'io.BytesIO', not 'io.StringIO'."128 )129 if isinstance(fileobj, io.TextIOBase):130 raise TypeError(131 "Multipart file uploads must be opened in binary mode, not text mode."132 )133134 self.filename = filename135 self.file = fileobj136 self.headers = headers
131 unmodified lines