@@ -36,13 +36,8 @@ The :mod:`urllib.request` module defines the following functions:
3636 *data * should be a buffer in the standard
3737 :mimetype: `application/x-www-form-urlencoded ` format. The
3838 :func: `urllib.parse.urlencode ` function takes a mapping or sequence of
39- 2-tuples and returns a string in this format. It should be encoded to bytes
40- before being used as the *data * parameter. The charset parameter in
41- ``Content-Type `` header may be used to specify the encoding. If charset
42- parameter is not sent with the Content-Type header, the server following the
43- HTTP 1.1 recommendation may assume that the data is encoded in ISO-8859-1
44- encoding. It is advisable to use charset parameter with encoding used in
45- ``Content-Type `` header with the :class: `Request `.
39+ 2-tuples and returns an ASCII text string in this format. It should
40+ be encoded to bytes before being used as the *data * parameter.
4641
4742 urllib.request module uses HTTP/1.1 and includes ``Connection:close `` header
4843 in its HTTP requests.
@@ -179,16 +174,9 @@ The following classes are provided:
179174 the only ones that use *data *; the HTTP request will be a POST instead of a
180175 GET when the *data * parameter is provided. *data * should be a buffer in the
181176 standard :mimetype: `application/x-www-form-urlencoded ` format.
182-
183177 The :func: `urllib.parse.urlencode ` function takes a mapping or sequence of
184- 2-tuples and returns a string in this format. It should be encoded to bytes
185- before being used as the *data * parameter. The charset parameter in
186- ``Content-Type `` header may be used to specify the encoding. If charset
187- parameter is not sent with the Content-Type header, the server following the
188- HTTP 1.1 recommendation may assume that the data is encoded in ISO-8859-1
189- encoding. It is advisable to use charset parameter with encoding used in
190- ``Content-Type `` header with the :class: `Request `.
191-
178+ 2-tuples and returns an ASCII string in this format. It should be
179+ encoded to bytes before being used as the *data * parameter.
192180
193181 *headers * should be a dictionary, and will be treated as if
194182 :meth: `add_header ` was called with each key and value as arguments.
@@ -201,7 +189,7 @@ The following classes are provided:
201189 ``"Python-urllib/2.6" `` (on Python 2.6).
202190
203191 An example of using ``Content-Type `` header with *data * argument would be
204- sending a dictionary like ``{"Content-Type":" application/x-www-form-urlencoded;charset=utf-8 "} ``.
192+ sending a dictionary like ``{"Content-Type": " application/x-www-form-urlencoded"} ``.
205193
206194 The final two arguments are only of interest for correct handling
207195 of third-party HTTP cookies:
@@ -1169,7 +1157,7 @@ every :class:`Request`. To change this::
11691157 opener.open('http://www.example.com/')
11701158
11711159Also, remember that a few standard headers (:mailheader: `Content-Length `,
1172- :mailheader: `Content-Type ` without charset parameter and :mailheader: `Host `)
1160+ :mailheader: `Content-Type ` and :mailheader: `Host `)
11731161are added when the :class: `Request ` is passed to :func: `urlopen ` (or
11741162:meth: `OpenerDirector.open `).
11751163
@@ -1192,11 +1180,8 @@ from urlencode is encoded to bytes before it is sent to urlopen as data::
11921180 >>> import urllib.request
11931181 >>> import urllib.parse
11941182 >>> data = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
1195- >>> data = data.encode('utf-8')
1196- >>> request = urllib.request.Request("http://requestb.in/xrbl82xr")
1197- >>> # adding charset parameter to the Content-Type header.
1198- >>> request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
1199- >>> with urllib.request.urlopen(request, data) as f:
1183+ >>> data = data.encode('ascii')
1184+ >>> with urllib.request.urlopen("http://requestb.in/xrbl82xr", data) as f:
12001185 ... print(f.read().decode('utf-8'))
12011186 ...
12021187
0 commit comments