summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <sigmavirus24@users.noreply.github.com>2014-12-13 13:49:04 -0600
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2014-12-13 13:49:04 -0600
commita8205bb5091bc0051bbd664deb4b1414558e7a87 (patch)
tree44a1224b7f2ffcb47c71b4df4f499b98c1b5ac1c
parente23bf10cf4ecc62f6c3dd6284043516fb833d9ce (diff)
parente8d02ea0bbc05042e618a7ca115f4fca7b2deeb9 (diff)
downloadpython-requests-a8205bb5091bc0051bbd664deb4b1414558e7a87.tar.gz
Merge pull request #2379 from arthurdarcet/master
utils.guess_filename fails if the given parameter looks like a file object but has a non-string name attribute
-rw-r--r--AUTHORS.rst1
-rw-r--r--requests/utils.py2
-rwxr-xr-xtest_requests.py8
3 files changed, 10 insertions, 1 deletions
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 71171d08..3f2a4d30 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -158,3 +158,4 @@ Patches and Suggestions
- Joe Alcorn (`@buttscicles <https://github.com/buttscicles>`_)
- Syed Suhail Ahmed <ssuhail.ahmed93@gmail.com> (`@syedsuhail <https://github.com/syedsuhail>`_)
- Scott Sadler (`@ssadler <https://github.com/ssadler>`_)
+- Arthur Darcet (`@arthurdarcet <https://github.com/arthurdarcet>`_)
diff --git a/requests/utils.py b/requests/utils.py
index aa5c140e..74679414 100644
--- a/requests/utils.py
+++ b/requests/utils.py
@@ -115,7 +115,7 @@ def get_netrc_auth(url):
def guess_filename(obj):
"""Tries to guess the filename of the given object."""
name = getattr(obj, 'name', None)
- if name and name[0] != '<' and name[-1] != '>':
+ if name and isinstance(name, builtin_str) and name[0] != '<' and name[-1] != '>':
return os.path.basename(name)
diff --git a/test_requests.py b/test_requests.py
index 2d3ee628..68ee08c5 100755
--- a/test_requests.py
+++ b/test_requests.py
@@ -928,6 +928,14 @@ class RequestsTestCase(unittest.TestCase):
assert 'multipart/form-data' in p.headers['Content-Type']
+ def test_can_send_file_object_with_non_string_filename(self):
+ f = io.BytesIO()
+ f.name = 2
+ r = requests.Request('POST', httpbin('post'), files={'f': f})
+ p = r.prepare()
+
+ assert 'multipart/form-data' in p.headers['Content-Type']
+
def test_autoset_header_values_are_native(self):
data = 'this is a string'
length = '16'