Skip to content
Myr

The library raises NoneType error when file-pointer (fp) resolves to None.

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

>>> 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.

authored by Rajiv Mayani · committed by Nate Prewitt · parent 5f09f0c · Browse files · 3 files+14 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+14 added−1 removed

  • tests:+8 added−0 removed
  • other:+6 added−1 removed

3 files+14 added−1 removed

modified:requests/models.py+5 added-1 removed
153 unmodified lines
154 fp = v155156 if isinstance(fp, (str, bytes, bytearray)):157 fdata = fp158 else:158 elif hasattr(fp, 'read'):159 fdata = fp.read()160 elif fp is None:161 continue162 else:163 fdata = fp164165 rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)166 rf.make_multipart(content_type=ft)167 new_fields.append(rf)
785 unmodified lines
modified:tests/test_requests.py+8 added
674 unmodified lines
675676 with pytest.raises(ValueError):677 requests.post(url, files=['bad file data'])678679 def test_invalid_files_input(self, httpbin):680681 url = httpbin('post')682 post = requests.post(url,683 files={"random-file-1": None, "random-file-2": 1})684 assert b'name="random-file-1"' not in post.request.body685 assert b'name="random-file-2"' in post.request.body686687 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):688689 class TestStream(object):690 def __init__(self, data):
1777 unmodified lines
modified:AUTHORS.rst+1 added
185 unmodified lines
186- Arthur Vigil (`@ahvigil <https://github.com/ahvigil>`_)187- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_)188- Demetrios Bairaktaris (`@DemetriosBairaktaris <https://github.com/demetriosbairaktaris>`_)189- Darren Dormer (`@ddormer <https://github.com/ddormer>`_)190- Rajiv Mayani (`@mayani <https://github.com/mayani>`_)