mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
The library raises NoneType error when file-pointer (fp) resolves to None.
>>> from requests import post
>>> r = post("https://example.com", files={"file-name": None})
However, when a param value or json field is None they are not included in the request body.
>>> from requests import get
>>> r = get("https://example.com", params={"file-name": None})
>>> r.request.url
This commit makes the beahviour consistent for files.
This commit is contained in:
committed by
Nate Prewitt
parent
5f09f0ca7e
commit
8546a15587
@@ -187,3 +187,4 @@ Patches and Suggestions
|
||||
- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_)
|
||||
- Demetrios Bairaktaris (`@DemetriosBairaktaris <https://github.com/demetriosbairaktaris>`_)
|
||||
- Darren Dormer (`@ddormer <https://github.com/ddormer>`_)
|
||||
- Rajiv Mayani (`@mayani <https://github.com/mayani>`_)
|
||||
|
||||
+5
-1
@@ -155,8 +155,12 @@ class RequestEncodingMixin(object):
|
||||
|
||||
if isinstance(fp, (str, bytes, bytearray)):
|
||||
fdata = fp
|
||||
else:
|
||||
elif hasattr(fp, 'read'):
|
||||
fdata = fp.read()
|
||||
elif fp is None:
|
||||
continue
|
||||
else:
|
||||
fdata = fp
|
||||
|
||||
rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)
|
||||
rf.make_multipart(content_type=ft)
|
||||
|
||||
@@ -676,6 +676,14 @@ class TestRequests:
|
||||
with pytest.raises(ValueError):
|
||||
requests.post(url, files=['bad file data'])
|
||||
|
||||
def test_invalid_files_input(self, httpbin):
|
||||
|
||||
url = httpbin('post')
|
||||
post = requests.post(url,
|
||||
files={"random-file-1": None, "random-file-2": 1})
|
||||
assert b'name="random-file-1"' not in post.request.body
|
||||
assert b'name="random-file-2"' in post.request.body
|
||||
|
||||
def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):
|
||||
|
||||
class TestStream(object):
|
||||
|
||||
Reference in New Issue
Block a user