summaryrefslogtreecommitdiffstats
path: root/Doc/howto/urllib2.rst
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-03-15 01:08:13 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-03-15 01:08:13 (GMT)
commit87684e6eeab154bf7d8775b767e2558ddf659745 (patch)
tree33d75a030e9abf280d91885f7dd79499fe0044b3 /Doc/howto/urllib2.rst
parent4552b2eccce8333521895d5212e324feb1dcc776 (diff)
downloadcpython-87684e6eeab154bf7d8775b767e2558ddf659745.zip
cpython-87684e6eeab154bf7d8775b767e2558ddf659745.tar.gz
cpython-87684e6eeab154bf7d8775b767e2558ddf659745.tar.bz2
Fix the wrong urllib exampls which use str for POST data. Closes Issue11261
Diffstat (limited to 'Doc/howto/urllib2.rst')
-rw-r--r--Doc/howto/urllib2.rst4
1 files changed, 3 insertions, 1 deletions
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
index 76286bd..567c1b1 100644
--- a/Doc/howto/urllib2.rst
+++ b/Doc/howto/urllib2.rst
@@ -108,6 +108,7 @@ library. ::
'language' : 'Python' }
data = urllib.parse.urlencode(values)
+ data = data.encode('utf-8') # data should be bytes
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read()
@@ -172,7 +173,8 @@ Explorer [#]_. ::
'language' : 'Python' }
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)
response = urllib.request.urlopen(req)
the_page = response.read()