@@ -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.
@@ -180,16 +175,9 @@ The following classes are provided:
180175 the only ones that use *data *; the HTTP request will be a POST instead of a
181176 GET when the *data * parameter is provided. *data * should be a buffer in the
182177 standard :mimetype: `application/x-www-form-urlencoded ` format.
183-
184178 The :func: `urllib.parse.urlencode ` function takes a mapping or sequence of
185- 2-tuples and returns a string in this format. It should be encoded to bytes
186- before being used as the *data * parameter. The charset parameter in
187- ``Content-Type `` header may be used to specify the encoding. If charset
188- parameter is not sent with the Content-Type header, the server following the
189- HTTP 1.1 recommendation may assume that the data is encoded in ISO-8859-1
190- encoding. It is advisable to use charset parameter with encoding used in
191- ``Content-Type `` header with the :class: `Request `.
192-
179+ 2-tuples and returns an ASCII string in this format. It should be
180+ encoded to bytes before being used as the *data * parameter.
193181
194182 *headers * should be a dictionary, and will be treated as if
195183 :meth: `add_header ` was called with each key and value as arguments.
@@ -202,7 +190,7 @@ The following classes are provided:
202190 ``"Python-urllib/2.6" `` (on Python 2.6).
203191
204192 An example of using ``Content-Type `` header with *data * argument would be
205- sending a dictionary like ``{"Content-Type":" application/x-www-form-urlencoded;charset=utf-8 "} ``.
193+ sending a dictionary like ``{"Content-Type": " application/x-www-form-urlencoded"} ``.
206194
207195 The final two arguments are only of interest for correct handling
208196 of third-party HTTP cookies:
@@ -1230,7 +1218,7 @@ every :class:`Request`. To change this::
12301218 opener.open('http://www.example.com/')
12311219
12321220Also, remember that a few standard headers (:mailheader: `Content-Length `,
1233- :mailheader: `Content-Type ` without charset parameter and :mailheader: `Host `)
1221+ :mailheader: `Content-Type ` and :mailheader: `Host `)
12341222are added when the :class: `Request ` is passed to :func: `urlopen ` (or
12351223:meth: `OpenerDirector.open `).
12361224
@@ -1253,11 +1241,8 @@ from urlencode is encoded to bytes before it is sent to urlopen as data::
12531241 >>> import urllib.request
12541242 >>> import urllib.parse
12551243 >>> data = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
1256- >>> data = data.encode('utf-8')
1257- >>> request = urllib.request.Request("http://requestb.in/xrbl82xr")
1258- >>> # adding charset parameter to the Content-Type header.
1259- >>> request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
1260- >>> with urllib.request.urlopen(request, data) as f:
1244+ >>> data = data.encode('ascii')
1245+ >>> with urllib.request.urlopen("http://requestb.in/xrbl82xr", data) as f:
12611246 ... print(f.read().decode('utf-8'))
12621247 ...
12631248
0 commit comments