Skip to content
Myr

utils.guess_filename fails if the given parameter looks like a file object but has a non-string name attribute

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

e.g. a cherrypy uploaded file behave like a regular file, except that its name attribute is an int and passing it directly to requests fails because of that

authored by Arthur Darcet · committed by Arthur Darcet · parent e23bf10 · Browse files · 3 files+10 added−1 removed
This commit

State

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

Diff stats

3 files+10 added−1 removed

  • other:+10 added−1 removed

3 files+10 added−1 removed

modified:requests/utils.py+1 added-1 removed
113 unmodified lines
114115def guess_filename(obj):116 """Tries to guess the filename of the given object."""117 name = getattr(obj, 'name', None)118 if name and name[0] != '<' and name[-1] != '>':118 if name and isinstance(name, builtin_str) and name[0] != '<' and name[-1] != '>':119 return os.path.basename(name)120121122def from_key_val_list(value):
575 unmodified lines
modified:AUTHORS.rst+1 added
156 unmodified lines
157- Martin Jul (`@mjul <https://github.com/mjul>`_)158- Joe Alcorn (`@buttscicles <https://github.com/buttscicles>`_)159- Syed Suhail Ahmed <ssuhail.ahmed93@gmail.com> (`@syedsuhail <https://github.com/syedsuhail>`_)160- Scott Sadler (`@ssadler <https://github.com/ssadler>`_)161- Arthur Darcet (`@arthurdarcet <https://github.com/arthurdarcet>`_)
modified:test_requests.py+8 added
926 unmodified lines
927 p = r.prepare()928929 assert 'multipart/form-data' in p.headers['Content-Type']930931 def test_can_send_file_object_with_non_string_filename(self):932 f = io.BytesIO()933 f.name = 2934 r = requests.Request('POST', httpbin('post'), files={'f': f})935 p = r.prepare()936937 assert 'multipart/form-data' in p.headers['Content-Type']938939 def test_autoset_header_values_are_native(self):940 data = 'this is a string'941 length = '16'942 req = requests.Request('POST', httpbin('post'), data=data)
611 unmodified lines