Add warnings about text/binary mode files.

This commit is contained in:
Cory Benfield
2015-10-14 13:23:19 +01:00
parent 18a6b60110
commit 7c55446b7e
2 changed files with 27 additions and 1 deletions
+19 -1
View File
@@ -315,6 +315,15 @@ file-like object for your body::
with open('massive-body', 'rb') as f:
requests.post('http://some.url/streamed', data=f)
.. warning:: It is strongly recommended that you open files in `binary mode`_.
This is because Requests may attempt to provide the
``Content-Length`` header for you, and if it does this value will
be set to the number of *bytes* in the file. Errors may occur if
you open the file in *text mode*.
.. _binary mode: https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
.. _chunk-encoding:
Chunk-Encoded Requests
@@ -362,6 +371,15 @@ To do that, just set files to a list of tuples of (form_field_name, file_info):
...
}
.. warning:: It is strongly recommended that you open files in `binary mode`_.
This is because Requests may attempt to provide the
``Content-Length`` header for you, and if it does this value will
be set to the number of *bytes* in the file. Errors may occur if
you open the file in *text mode*.
.. _binary mode: https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
.. _event-hooks:
Event Hooks
@@ -519,7 +537,7 @@ any request to the given scheme and exact hostname.
}
Note that proxy URLs must include the scheme.
.. _compliance:
Compliance
+8
View File
@@ -302,6 +302,14 @@ support this, but there is a separate package which does -
For sending multiple files in one request refer to the :ref:`advanced <advanced>`
section.
.. warning:: It is strongly recommended that you open files in `binary mode`_.
This is because Requests may attempt to provide the
``Content-Length`` header for you, and if it does this value will
be set to the number of *bytes* in the file. Errors may occur if
you open the file in *text mode*.
.. _binary mode: https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
Response Status Codes
---------------------