Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7596aeab
Commit
7596aeab
authored
Mar 14, 2012
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Plain Diff
cpython:Fix the wrong urllib exampls which use str for POST data. Closes Issue11261
parents
3d7c878f
87684e6e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
Doc/howto/urllib2.rst
Doc/howto/urllib2.rst
+3
-1
Doc/library/urllib.request.rst
Doc/library/urllib.request.rst
+8
-9
No files found.
Doc/howto/urllib2.rst
View file @
7596aeab
...
@@ -115,6 +115,7 @@ library. ::
...
@@ -115,6 +115,7 @@ library. ::
'language' : 'Python' }
'language' : 'Python' }
data = urllib.parse.urlencode(values)
data = urllib.parse.urlencode(values)
data = data.encode('utf-8') # data should be bytes
req = urllib.request.Request(url, data)
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
response = urllib.request.urlopen(req)
the_page = response.read()
the_page = response.read()
...
@@ -180,6 +181,7 @@ Explorer [#]_. ::
...
@@ -180,6 +181,7 @@ Explorer [#]_. ::
headers = { 'User-Agent' : user_agent }
headers = { 'User-Agent' : user_agent }
data = urllib.parse.urlencode(values)
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
req = urllib.request.Request(url, data, headers)
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req)
response = urllib.request.urlopen(req)
the_page = response.read()
the_page = response.read()
...
...
Doc/library/urllib.request.rst
View file @
7596aeab
...
@@ -138,14 +138,13 @@ The following classes are provided:
...
@@ -138,14 +138,13 @@ The following classes are provided:
*url* should be a string containing a valid URL.
*url* should be a string containing a valid URL.
*data* may be a string specifying additional data to send to the
*data* may be a bytes object specifying additional data to send to the
server, or ``None`` if no such data is needed. Currently HTTP
server, or ``None`` if no such data is needed. Currently HTTP requests are
requests are the only ones that use *data*, in order to choose between
the only ones that use *data*; the HTTP request will be a POST instead of a
``'GET'`` and ``'POST'`` when *method* is not specified.
GET when the *data* parameter is provided. *data* should be a buffer in the
*data* should be a buffer in the standard
standard :mimetype:`application/x-www-form-urlencoded` format. The
:mimetype:`application/x-www-form-urlencoded` format. The
:func:`urllib.parse.urlencode` function takes a mapping or sequence of
:func:`urllib.parse.urlencode` function takes a mapping or sequence
2-tuples and returns a string in this format.
of 2-tuples and returns a string in this format.
*headers* should be a dictionary, and will be treated as if
*headers* should be a dictionary, and will be treated as if
:meth:`add_header` was called with each key and value as arguments.
:meth:`add_header` was called with each key and value as arguments.
...
@@ -1183,7 +1182,7 @@ some point in the future.
...
@@ -1183,7 +1182,7 @@ some point in the future.
If the *url* uses the :file:`http:` scheme identifier, the optional *data*
If the *url* uses the :file:`http:` scheme identifier, the optional *data*
argument may be given to specify a ``POST`` request (normally the request
argument may be given to specify a ``POST`` request (normally the request
type is ``GET``). The *data* argument must in standard
type is ``GET``). The *data* argument must
be a bytes object
in standard
:mimetype:`application/x-www-form-urlencoded` format; see the
:mimetype:`application/x-www-form-urlencoded` format; see the
:func:`urlencode` function below.
:func:`urlencode` function below.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment