/
usr
/
share
/
doc
/
python2-docs
/
html
/
library
/
/usr/share/doc/python2-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
59507
0644
edit
dl
rm
abc.html
25826
0644
edit
dl
rm
aepack.html
14164
0644
edit
dl
rm
aetools.html
16389
0644
edit
dl
rm
aetypes.html
21021
0644
edit
dl
rm
aifc.html
25064
0644
edit
dl
rm
al.html
18672
0644
edit
dl
rm
allos.html
35297
0644
edit
dl
rm
anydbm.html
18124
0644
edit
dl
rm
archiving.html
10078
0644
edit
dl
rm
argparse.html
263616
0644
edit
dl
rm
array.html
31855
0644
edit
dl
rm
ast.html
38167
0644
edit
dl
rm
asynchat.html
33930
0644
edit
dl
rm
asyncore.html
40631
0644
edit
dl
rm
atexit.html
18455
0644
edit
dl
rm
audioop.html
34252
0644
edit
dl
rm
autogil.html
8733
0644
edit
dl
rm
base64.html
21862
0644
edit
dl
rm
basehttpserver.html
37441
0644
edit
dl
rm
bastion.html
11798
0644
edit
dl
rm
bdb.html
41395
0644
edit
dl
rm
binascii.html
22997
0644
edit
dl
rm
binhex.html
11309
0644
edit
dl
rm
bisect.html
24666
0644
edit
dl
rm
bsddb.html
28589
0644
edit
dl
rm
bz2.html
29048
0644
edit
dl
rm
calendar.html
41762
0644
edit
dl
rm
carbon.html
51998
0644
edit
dl
rm
cd.html
30033
0644
edit
dl
rm
cgi.html
55922
0644
edit
dl
rm
cgihttpserver.html
14026
0644
edit
dl
rm
cgitb.html
12263
0644
edit
dl
rm
chunk.html
15899
0644
edit
dl
rm
cmath.html
28365
0644
edit
dl
rm
cmd.html
29042
0644
edit
dl
rm
code.html
26959
0644
edit
dl
rm
codecs.html
118258
0644
edit
dl
rm
codeop.html
15898
0644
edit
dl
rm
collections.html
147647
0644
edit
dl
rm
colorpicker.html
8035
0644
edit
dl
rm
colorsys.html
11919
0644
edit
dl
rm
commands.html
15516
0644
edit
dl
rm
compileall.html
18621
0644
edit
dl
rm
compiler.html
75897
0644
edit
dl
rm
configparser.html
67751
0644
edit
dl
rm
constants.html
13979
0644
edit
dl
rm
contextlib.html
22777
0644
edit
dl
rm
cookie.html
41854
0644
edit
dl
rm
cookielib.html
91032
0644
edit
dl
rm
copy.html
13004
0644
edit
dl
rm
copy_reg.html
14691
0644
edit
dl
rm
crypt.html
10647
0644
edit
dl
rm
crypto.html
7761
0644
edit
dl
rm
csv.html
76456
0644
edit
dl
rm
ctypes.html
264575
0644
edit
dl
rm
curses.ascii.html
24873
0644
edit
dl
rm
curses.html
167501
0644
edit
dl
rm
curses.panel.html
15824
0644
edit
dl
rm
custominterp.html
8026
0644
edit
dl
rm
datatypes.html
18015
0644
edit
dl
rm
datetime.html
253438
0644
edit
dl
rm
dbhash.html
16825
0644
edit
dl
rm
dbm.html
13507
0644
edit
dl
rm
debug.html
10703
0644
edit
dl
rm
decimal.html
222315
0644
edit
dl
rm
development.html
14828
0644
edit
dl
rm
difflib.html
91975
0644
edit
dl
rm
dircache.html
12299
0644
edit
dl
rm
dis.html
84156
0644
edit
dl
rm
distribution.html
7679
0644
edit
dl
rm
distutils.html
10152
0644
edit
dl
rm
dl.html
17668
0644
edit
dl
rm
doctest.html
185883
0644
edit
dl
rm
docxmlrpcserver.html
17573
0644
edit
dl
rm
dumbdbm.html
15549
0644
edit
dl
rm
dummy_thread.html
10065
0644
edit
dl
rm
dummy_threading.html
8934
0644
edit
dl
rm
easydialogs.html
33124
0644
edit
dl
rm
email-examples.html
47424
0644
edit
dl
rm
email.charset.html
29424
0644
edit
dl
rm
email.encoders.html
12847
0644
edit
dl
rm
email.errors.html
17952
0644
edit
dl
rm
email.generator.html
23141
0644
edit
dl
rm
email.header.html
29108
0644
edit
dl
rm
email.html
55722
0644
edit
dl
rm
email.iterators.html
12623
0644
edit
dl
rm
email.message.html
70189
0644
edit
dl
rm
email.mime.html
31655
0644
edit
dl
rm
email.parser.html
35142
0644
edit
dl
rm
email.utils.html
27076
0644
edit
dl
rm
ensurepip.html
18327
0644
edit
dl
rm
errno.html
40246
0644
edit
dl
rm
exceptions.html
63693
0644
edit
dl
rm
fcntl.html
26245
0644
edit
dl
rm
filecmp.html
23997
0644
edit
dl
rm
fileformats.html
9653
0644
edit
dl
rm
fileinput.html
27071
0644
edit
dl
rm
filesys.html
10866
0644
edit
dl
rm
fl.html
56525
0644
edit
dl
rm
fm.html
13009
0644
edit
dl
rm
fnmatch.html
16258
0644
edit
dl
rm
formatter.html
37371
0644
edit
dl
rm
fpectl.html
16879
0644
edit
dl
rm
fpformat.html
11455
0644
edit
dl
rm
fractions.html
24888
0644
edit
dl
rm
framework.html
36934
0644
edit
dl
rm
frameworks.html
7551
0644
edit
dl
rm
ftplib.html
49577
0644
edit
dl
rm
functions.html
205640
0644
edit
dl
rm
functools.html
29645
0644
edit
dl
rm
future_builtins.html
14477
0644
edit
dl
rm
gc.html
28423
0644
edit
dl
rm
gdbm.html
17805
0644
edit
dl
rm
gensuitemodule.html
12574
0644
edit
dl
rm
getopt.html
25280
0644
edit
dl
rm
getpass.html
11426
0644
edit
dl
rm
gettext.html
84971
0644
edit
dl
rm
gl.html
24342
0644
edit
dl
rm
glob.html
14430
0644
edit
dl
rm
grp.html
11316
0644
edit
dl
rm
gzip.html
20576
0644
edit
dl
rm
hashlib.html
25467
0644
edit
dl
rm
heapq.html
34890
0644
edit
dl
rm
hmac.html
14374
0644
edit
dl
rm
hotshot.html
20147
0644
edit
dl
rm
htmllib.html
27682
0644
edit
dl
rm
htmlparser.html
42433
0644
edit
dl
rm
httplib.html
70932
0644
edit
dl
rm
i18n.html
10047
0644
edit
dl
rm
ic.html
18654
0644
edit
dl
rm
idle.html
42148
0644
edit
dl
rm
imageop.html
16099
0644
edit
dl
rm
imaplib.html
58515
0644
edit
dl
rm
imgfile.html
12732
0644
edit
dl
rm
imghdr.html
12238
0644
edit
dl
rm
imp.html
37603
0644
edit
dl
rm
importlib.html
8926
0644
edit
dl
rm
imputil.html
33563
0644
edit
dl
rm
index.html
79088
0644
edit
dl
rm
inspect.html
56823
0644
edit
dl
rm
internet.html
26138
0644
edit
dl
rm
intro.html
9353
0644
edit
dl
rm
io.html
113701
0644
edit
dl
rm
ipc.html
16598
0644
edit
dl
rm
itertools.html
125397
0644
edit
dl
rm
jpeg.html
13757
0644
edit
dl
rm
json.html
73678
0644
edit
dl
rm
keyword.html
8210
0644
edit
dl
rm
language.html
11687
0644
edit
dl
rm
linecache.html
11416
0644
edit
dl
rm
locale.html
61576
0644
edit
dl
rm
logging.config.html
80045
0644
edit
dl
rm
logging.handlers.html
80194
0644
edit
dl
rm
logging.html
110254
0644
edit
dl
rm
mac.html
23376
0644
edit
dl
rm
macos.html
16129
0644
edit
dl
rm
macosa.html
14080
0644
edit
dl
rm
macostools.html
16898
0644
edit
dl
rm
macpath.html
8386
0644
edit
dl
rm
mailbox.html
171121
0644
edit
dl
rm
mailcap.html
14132
0644
edit
dl
rm
markup.html
19862
0644
edit
dl
rm
marshal.html
19456
0644
edit
dl
rm
math.html
44015
0644
edit
dl
rm
md5.html
15123
0644
edit
dl
rm
mhlib.html
24123
0644
edit
dl
rm
mimetools.html
21206
0644
edit
dl
rm
mimetypes.html
30634
0644
edit
dl
rm
mimewriter.html
16078
0644
edit
dl
rm
mimify.html
15279
0644
edit
dl
rm
miniaeframe.html
13109
0644
edit
dl
rm
misc.html
7236
0644
edit
dl
rm
mm.html
9570
0644
edit
dl
rm
mmap.html
30832
0644
edit
dl
rm
modulefinder.html
18096
0644
edit
dl
rm
modules.html
9017
0644
edit
dl
rm
msilib.html
57853
0644
edit
dl
rm
msvcrt.html
21232
0644
edit
dl
rm
multifile.html
26256
0644
edit
dl
rm
multiprocessing.html
414535
0644
edit
dl
rm
mutex.html
12147
0644
edit
dl
rm
netdata.html
18379
0644
edit
dl
rm
netrc.html
14021
0644
edit
dl
rm
new.html
13177
0644
edit
dl
rm
nis.html
11502
0644
edit
dl
rm
nntplib.html
45689
0644
edit
dl
rm
numbers.html
40636
0644
edit
dl
rm
numeric.html
14292
0644
edit
dl
rm
operator.html
93622
0644
edit
dl
rm
optparse.html
250109
0644
edit
dl
rm
os.html
240195
0644
edit
dl
rm
os.path.html
43402
0644
edit
dl
rm
ossaudiodev.html
45594
0644
edit
dl
rm
othergui.html
9403
0644
edit
dl
rm
parser.html
42558
0644
edit
dl
rm
pdb.html
38603
0644
edit
dl
rm
persistence.html
15676
0644
edit
dl
rm
pickle.html
109684
0644
edit
dl
rm
pickletools.html
11475
0644
edit
dl
rm
pipes.html
19685
0644
edit
dl
rm
pkgutil.html
27367
0644
edit
dl
rm
platform.html
31599
0644
edit
dl
rm
plistlib.html
18344
0644
edit
dl
rm
popen2.html
27601
0644
edit
dl
rm
poplib.html
24320
0644
edit
dl
rm
posix.html
16626
0644
edit
dl
rm
posixfile.html
21387
0644
edit
dl
rm
pprint.html
32207
0644
edit
dl
rm
profile.html
72788
0644
edit
dl
rm
pty.html
10195
0644
edit
dl
rm
pwd.html
12388
0644
edit
dl
rm
pyclbr.html
15812
0644
edit
dl
rm
pydoc.html
13650
0644
edit
dl
rm
pyexpat.html
80886
0644
edit
dl
rm
python.html
12854
0644
edit
dl
rm
py_compile.html
11932
0644
edit
dl
rm
queue.html
26856
0644
edit
dl
rm
quopri.html
12739
0644
edit
dl
rm
random.html
42722
0644
edit
dl
rm
re.html
155985
0644
edit
dl
rm
readline.html
37383
0644
edit
dl
rm
repr.html
21778
0644
edit
dl
rm
resource.html
28286
0644
edit
dl
rm
restricted.html
12366
0644
edit
dl
rm
rexec.html
40566
0644
edit
dl
rm
rfc822.html
46408
0644
edit
dl
rm
rlcompleter.html
14460
0644
edit
dl
rm
robotparser.html
13403
0644
edit
dl
rm
runpy.html
21925
0644
edit
dl
rm
sched.html
19878
0644
edit
dl
rm
scrolledtext.html
9728
0644
edit
dl
rm
select.html
44090
0644
edit
dl
rm
sets.html
40151
0644
edit
dl
rm
sgi.html
10371
0644
edit
dl
rm
sgmllib.html
34464
0644
edit
dl
rm
sha.html
13062
0644
edit
dl
rm
shelve.html
29955
0644
edit
dl
rm
shlex.html
35033
0644
edit
dl
rm
shutil.html
45454
0644
edit
dl
rm
signal.html
34023
0644
edit
dl
rm
simplehttpserver.html
20351
0644
edit
dl
rm
simplexmlrpcserver.html
37794
0644
edit
dl
rm
site.html
26887
0644
edit
dl
rm
smtpd.html
13587
0644
edit
dl
rm
smtplib.html
47054
0644
edit
dl
rm
sndhdr.html
10993
0644
edit
dl
rm
socket.html
116414
0644
edit
dl
rm
socketserver.html
76430
0644
edit
dl
rm
someos.html
16472
0644
edit
dl
rm
spwd.html
11163
0644
edit
dl
rm
sqlite3.html
150014
0644
edit
dl
rm
ssl.html
202453
0644
edit
dl
rm
stat.html
34597
0644
edit
dl
rm
statvfs.html
11326
0644
edit
dl
rm
stdtypes.html
298144
0644
edit
dl
rm
string.html
120219
0644
edit
dl
rm
stringio.html
20061
0644
edit
dl
rm
stringprep.html
17729
0644
edit
dl
rm
strings.html
15905
0644
edit
dl
rm
struct.html
44896
0644
edit
dl
rm
subprocess.html
110447
0644
edit
dl
rm
sun.html
7253
0644
edit
dl
rm
sunau.html
30011
0644
edit
dl
rm
sunaudio.html
19236
0644
edit
dl
rm
symbol.html
8140
0644
edit
dl
rm
symtable.html
25871
0644
edit
dl
rm
sys.html
110996
0644
edit
dl
rm
sysconfig.html
26299
0644
edit
dl
rm
syslog.html
19737
0644
edit
dl
rm
tabnanny.html
11393
0644
edit
dl
rm
tarfile.html
88728
0644
edit
dl
rm
telnetlib.html
27782
0644
edit
dl
rm
tempfile.html
31903
0644
edit
dl
rm
termios.html
17309
0644
edit
dl
rm
test.html
57030
0644
edit
dl
rm
textwrap.html
30135
0644
edit
dl
rm
thread.html
21486
0644
edit
dl
rm
threading.html
86655
0644
edit
dl
rm
time.html
63798
0644
edit
dl
rm
timeit.html
40529
0644
edit
dl
rm
tix.html
50582
0644
edit
dl
rm
tk.html
26568
0644
edit
dl
rm
tkinter.html
84316
0644
edit
dl
rm
token.html
20999
0644
edit
dl
rm
tokenize.html
20607
0644
edit
dl
rm
trace.html
28668
0644
edit
dl
rm
traceback.html
40900
0644
edit
dl
rm
ttk.html
108515
0644
edit
dl
rm
tty.html
9753
0644
edit
dl
rm
turtle.html
230483
0644
edit
dl
rm
types.html
29833
0644
edit
dl
rm
undoc.html
24680
0644
edit
dl
rm
unicodedata.html
20186
0644
edit
dl
rm
unittest.html
225021
0644
edit
dl
rm
unix.html
11223
0644
edit
dl
rm
urllib.html
68266
0644
edit
dl
rm
urllib2.html
113380
0644
edit
dl
rm
urlparse.html
43474
0644
edit
dl
rm
user.html
12707
0644
edit
dl
rm
userdict.html
32069
0644
edit
dl
rm
uu.html
11810
0644
edit
dl
rm
uuid.html
30137
0644
edit
dl
rm
warnings.html
50950
0644
edit
dl
rm
wave.html
24894
0644
edit
dl
rm
weakref.html
38808
0644
edit
dl
rm
webbrowser.html
26565
0644
edit
dl
rm
whichdb.html
9499
0644
edit
dl
rm
windows.html
9817
0644
edit
dl
rm
winsound.html
20466
0644
edit
dl
rm
wsgiref.html
88384
0644
edit
dl
rm
xdrlib.html
33018
0644
edit
dl
rm
xml.dom.html
97877
0644
edit
dl
rm
xml.dom.minidom.html
43230
0644
edit
dl
rm
xml.dom.pulldom.html
13835
0644
edit
dl
rm
xml.etree.elementtree.html
111804
0644
edit
dl
rm
xml.html
18007
0644
edit
dl
rm
xml.sax.handler.html
41877
0644
edit
dl
rm
xml.sax.html
23458
0644
edit
dl
rm
xml.sax.reader.html
44802
0644
edit
dl
rm
xml.sax.utils.html
16087
0644
edit
dl
rm
xmlrpclib.html
69191
0644
edit
dl
rm
zipfile.html
62227
0644
edit
dl
rm
zipimport.html
22769
0644
edit
dl
rm
zlib.html
31230
0644
edit
dl
rm
_winreg.html
64631
0644
edit
dl
rm
__builtin__.html
11069
0644
edit
dl
rm
__future__.html
14688
0644
edit
dl
rm
__main__.html
7512
0644
edit
dl
rm
Edit:
/usr/share/doc/python2-docs/html/library/urllib.html
(68266B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>20.5. urllib — Open arbitrary resources by URL — Python 2.7.16 documentation</title> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.16 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="20.6. urllib2 — extensible library for opening URLs" href="urllib2.html" /> <link rel="prev" title="20.4. wsgiref — WSGI Utilities and Reference Implementation" href="wsgiref.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/2/library/urllib.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="urllib2.html" title="20.6. urllib2 — extensible library for opening URLs" accesskey="N">next</a> |</li> <li class="right" > <a href="wsgiref.html" title="20.4. wsgiref — WSGI Utilities and Reference Implementation" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.16 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">20. Internet Protocols and Support</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-urllib"> <span id="urllib-open-arbitrary-resources-by-url"></span><h1>20.5. <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> — Open arbitrary resources by URL<a class="headerlink" href="#module-urllib" title="Permalink to this headline">¶</a></h1> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> module has been split into parts and renamed in Python 3 to <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code>, and <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.error</span></code>. The <a class="reference internal" href="../glossary.html#term-2to3"><span class="xref std std-term">2to3</span></a> tool will automatically adapt imports when converting your sources to Python 3. Also note that the <code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.request.urlopen()</span></code> function in Python 3 is equivalent to <a class="reference internal" href="urllib2.html#urllib2.urlopen" title="urllib2.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib2.urlopen()</span></code></a> and that <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.urlopen()</span></code></a> has been removed.</p> </div> <p id="index-0">This module provides a high-level interface for fetching data across the World Wide Web. In particular, the <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> function is similar to the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, but accepts Universal Resource Locators (URLs) instead of filenames. Some restrictions apply — it can only open URLs for reading, and no seek operations are available.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last">The <a class="reference external" href="http://docs.python-requests.org/">Requests package</a> is recommended for a higher-level HTTP client interface.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.7.9: </span>For HTTPS URIs, <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> performs all the neccessary certificate and hostname checks by default.</p> </div> <div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">For Python versions earlier than 2.7.9, urllib does not attempt to validate the server certificates of HTTPS URIs. Use at your own risk!</p> </div> <div class="section" id="high-level-interface"> <h2>20.5.1. High-level interface<a class="headerlink" href="#high-level-interface" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="urllib.urlopen"> <code class="descclassname">urllib.</code><code class="descname">urlopen</code><span class="sig-paren">(</span><em>url</em><span class="optional">[</span>, <em>data</em><span class="optional">[</span>, <em>proxies</em><span class="optional">[</span>, <em>context</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.urlopen" title="Permalink to this definition">¶</a></dt> <dd><p>Open a network object denoted by a URL for reading. If the URL does not have a scheme identifier, or if it has <code class="file docutils literal notranslate"><span class="pre">file:</span></code> as its scheme identifier, this opens a local file (without <a class="reference internal" href="../glossary.html#term-universal-newlines"><span class="xref std std-term">universal newlines</span></a>); otherwise it opens a socket to a server somewhere on the network. If the connection cannot be made the <a class="reference internal" href="exceptions.html#exceptions.IOError" title="exceptions.IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a> exception is raised. If all went well, a file-like object is returned. This supports the following methods: <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code>, <a class="reference internal" href="readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readline()</span></code></a>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">readlines()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">getcode()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">geturl()</span></code>. It also has proper support for the <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a> protocol. One caveat: the <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case.</p> <p>Except for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">getcode()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">geturl()</span></code> methods, these methods have the same interface as for file objects — see section <a class="reference internal" href="stdtypes.html#bltin-file-objects"><span class="std std-ref">File Objects</span></a> in this manual. (It is not a built-in file object, however, so it can’t be used at those few places where a true built-in file object is required.)</p> <p id="index-1">The <code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code> method returns an instance of the class <a class="reference internal" href="mimetools.html#mimetools.Message" title="mimetools.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">mimetools.Message</span></code></a> containing meta-information associated with the URL. When the method is HTTP, these headers are those returned by the server at the head of the retrieved HTML page (including Content-Length and Content-Type). When the method is FTP, a Content-Length header will be present if (as is now usual) the server passed back a file length in response to the FTP retrieval request. A Content-Type header will be present if the MIME type can be guessed. When the method is local-file, returned headers will include a Date representing the file’s last-modified time, a Content-Length giving file size, and a Content-Type containing a guess at the file’s type. See also the description of the <a class="reference internal" href="mimetools.html#module-mimetools" title="mimetools: Tools for parsing MIME-style message bodies. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetools</span></code></a> module.</p> <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">geturl()</span></code> method returns the real URL of the page. In some cases, the HTTP server redirects a client to another URL. The <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> function handles this transparently, but in some cases the caller needs to know which URL the client was redirected to. The <code class="xref py py-meth docutils literal notranslate"><span class="pre">geturl()</span></code> method can be used to get at this redirected URL.</p> <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">getcode()</span></code> method returns the HTTP status code that was sent with the response, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the URL is no HTTP URL.</p> <p>If the <em>url</em> uses the <code class="file docutils literal notranslate"><span class="pre">http:</span></code> scheme identifier, the optional <em>data</em> argument may be given to specify a <code class="docutils literal notranslate"><span class="pre">POST</span></code> request (normally the request type is <code class="docutils literal notranslate"><span class="pre">GET</span></code>). The <em>data</em> argument must be in standard <em class="mimetype">application/x-www-form-urlencoded</em> format; see the <a class="reference internal" href="#urllib.urlencode" title="urllib.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlencode()</span></code></a> function below.</p> <p>The <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> function works transparently with proxies which do not require authentication. In a Unix or Windows environment, set the <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">http_proxy</span></code>, or <span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">ftp_proxy</span></code> environment variables to a URL that identifies the proxy server before starting the Python interpreter. For example (the <code class="docutils literal notranslate"><span class="pre">'%'</span></code> is the command prompt):</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">%</span> <span class="n">http_proxy</span><span class="o">=</span><span class="s2">"http://www.someproxy.com:3128"</span> <span class="o">%</span> <span class="n">export</span> <span class="n">http_proxy</span> <span class="o">%</span> <span class="n">python</span> <span class="o">...</span> </pre></div> </div> <p>The <span class="target" id="index-4"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">no_proxy</span></code> environment variable can be used to specify hosts which shouldn’t be reached via proxy; if set, it should be a comma-separated list of hostname suffixes, optionally with <code class="docutils literal notranslate"><span class="pre">:port</span></code> appended, for example <code class="docutils literal notranslate"><span class="pre">cern.ch,ncsa.uiuc.edu,some.host:8080</span></code>.</p> <p>In a Windows environment, if no proxy environment variables are set, proxy settings are obtained from the registry’s Internet Settings section.</p> <p id="index-5">In a Mac OS X environment, <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> will retrieve proxy information from the OS X System Configuration Framework, which can be managed with Network System Preferences panel.</p> <p>Alternatively, the optional <em>proxies</em> argument may be used to explicitly specify proxies. It must be a dictionary mapping scheme names to proxy URLs, where an empty dictionary causes no proxies to be used, and <code class="docutils literal notranslate"><span class="pre">None</span></code> (the default value) causes environmental proxy settings to be used as discussed above. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Use http://www.someproxy.com:3128 for HTTP proxying</span> <span class="n">proxies</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'http'</span><span class="p">:</span> <span class="s1">'http://www.someproxy.com:3128'</span><span class="p">}</span> <span class="n">filehandle</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">some_url</span><span class="p">,</span> <span class="n">proxies</span><span class="o">=</span><span class="n">proxies</span><span class="p">)</span> <span class="c1"># Don't use any proxies</span> <span class="n">filehandle</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">some_url</span><span class="p">,</span> <span class="n">proxies</span><span class="o">=</span><span class="p">{})</span> <span class="c1"># Use proxies from environment - both versions are equivalent</span> <span class="n">filehandle</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">some_url</span><span class="p">,</span> <span class="n">proxies</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="n">filehandle</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">some_url</span><span class="p">)</span> </pre></div> </div> <p>Proxies which require authentication for use are not currently supported; this is considered an implementation limitation.</p> <p>The <em>context</em> parameter may be set to a <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance to configure the SSL settings that are used if <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> makes a HTTPS connection.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.3: </span>Added the <em>proxies</em> support.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.6: </span>Added <code class="xref py py-meth docutils literal notranslate"><span class="pre">getcode()</span></code> to returned object and support for the <span class="target" id="index-6"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">no_proxy</span></code> environment variable.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.7.9: </span>The <em>context</em> parameter was added. All the neccessary certificate and hostname checks are done by default.</p> </div> <div class="deprecated"> <p><span class="versionmodified">Deprecated since version 2.6: </span>The <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> function has been removed in Python 3 in favor of <a class="reference internal" href="urllib2.html#urllib2.urlopen" title="urllib2.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib2.urlopen()</span></code></a>.</p> </div> </dd></dl> <dl class="function"> <dt id="urllib.urlretrieve"> <code class="descclassname">urllib.</code><code class="descname">urlretrieve</code><span class="sig-paren">(</span><em>url</em><span class="optional">[</span>, <em>filename</em><span class="optional">[</span>, <em>reporthook</em><span class="optional">[</span>, <em>data</em><span class="optional">[</span>, <em>context</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.urlretrieve" title="Permalink to this definition">¶</a></dt> <dd><p>Copy a network object denoted by a URL to a local file, if necessary. If the URL points to a local file, or a valid cached copy of the object exists, the object is not copied. Return a tuple <code class="docutils literal notranslate"><span class="pre">(filename,</span> <span class="pre">headers)</span></code> where <em>filename</em> is the local file name under which the object can be found, and <em>headers</em> is whatever the <code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code> method of the object returned by <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> returned (for a remote object, possibly cached). Exceptions are the same as for <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a>.</p> <p>The second argument, if present, specifies the file location to copy to (if absent, the location will be a tempfile with a generated name). The third argument, if present, is a callable that will be called once on establishment of the network connection and once after each block read thereafter. The callable will be passed three arguments; a count of blocks transferred so far, a block size in bytes, and the total size of the file. The third argument may be <code class="docutils literal notranslate"><span class="pre">-1</span></code> on older FTP servers which do not return a file size in response to a retrieval request.</p> <p>If the <em>url</em> uses the <code class="file docutils literal notranslate"><span class="pre">http:</span></code> scheme identifier, the optional <em>data</em> argument may be given to specify a <code class="docutils literal notranslate"><span class="pre">POST</span></code> request (normally the request type is <code class="docutils literal notranslate"><span class="pre">GET</span></code>). The <em>data</em> argument must in standard <em class="mimetype">application/x-www-form-urlencoded</em> format; see the <a class="reference internal" href="#urllib.urlencode" title="urllib.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlencode()</span></code></a> function below.</p> <p>The <em>context</em> parameter may be set to a <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance to configure the SSL settings that are used if <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> makes a HTTPS connection.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.5: </span><a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> will raise <a class="reference internal" href="#urllib.ContentTooShortError" title="urllib.ContentTooShortError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ContentTooShortError</span></code></a> when it detects that the amount of data available was less than the expected amount (which is the size reported by a <em>Content-Length</em> header). This can occur, for example, when the download is interrupted.</p> <p>The <em>Content-Length</em> is treated as a lower bound: if there’s more data to read, <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> reads more data, but if less data is available, it raises the exception.</p> <p>You can still retrieve the downloaded data in this case, it is stored in the <code class="xref py py-attr docutils literal notranslate"><span class="pre">content</span></code> attribute of the exception instance.</p> <p>If no <em>Content-Length</em> header was supplied, <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> can not check the size of the data it has downloaded, and just returns it. In this case you just have to assume that the download was successful.</p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.7.9: </span>The <em>context</em> parameter was added. All the neccessary certificate and hostname checks are done by default.</p> </div> </dd></dl> <dl class="data"> <dt id="urllib._urlopener"> <code class="descclassname">urllib.</code><code class="descname">_urlopener</code><a class="headerlink" href="#urllib._urlopener" title="Permalink to this definition">¶</a></dt> <dd><p>The public functions <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> and <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> create an instance of the <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> class and use it to perform their requested actions. To override this functionality, programmers can create a subclass of <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> or <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a>, then assign an instance of that class to the <code class="docutils literal notranslate"><span class="pre">urllib._urlopener</span></code> variable before calling the desired function. For example, applications may want to specify a different <em class="mailheader">User-Agent</em> header than <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> defines. This can be accomplished with the following code:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">urllib</span> <span class="k">class</span> <span class="nc">AppURLopener</span><span class="p">(</span><span class="n">urllib</span><span class="o">.</span><span class="n">FancyURLopener</span><span class="p">):</span> <span class="n">version</span> <span class="o">=</span> <span class="s2">"App/1.7"</span> <span class="n">urllib</span><span class="o">.</span><span class="n">_urlopener</span> <span class="o">=</span> <span class="n">AppURLopener</span><span class="p">()</span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="urllib.urlcleanup"> <code class="descclassname">urllib.</code><code class="descname">urlcleanup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.urlcleanup" title="Permalink to this definition">¶</a></dt> <dd><p>Clear the cache that may have been built up by previous calls to <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a>.</p> </dd></dl> </div> <div class="section" id="utility-functions"> <h2>20.5.2. Utility functions<a class="headerlink" href="#utility-functions" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="urllib.quote"> <code class="descclassname">urllib.</code><code class="descname">quote</code><span class="sig-paren">(</span><em>string</em><span class="optional">[</span>, <em>safe</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.quote" title="Permalink to this definition">¶</a></dt> <dd><p>Replace special characters in <em>string</em> using the <code class="docutils literal notranslate"><span class="pre">%xx</span></code> escape. Letters, digits, and the characters <code class="docutils literal notranslate"><span class="pre">'_.-'</span></code> are never quoted. By default, this function is intended for quoting the path section of the URL. The optional <em>safe</em> parameter specifies additional characters that should not be quoted — its default value is <code class="docutils literal notranslate"><span class="pre">'/'</span></code>.</p> <p>Example: <code class="docutils literal notranslate"><span class="pre">quote('/~connolly/')</span></code> yields <code class="docutils literal notranslate"><span class="pre">'/%7econnolly/'</span></code>.</p> </dd></dl> <dl class="function"> <dt id="urllib.quote_plus"> <code class="descclassname">urllib.</code><code class="descname">quote_plus</code><span class="sig-paren">(</span><em>string</em><span class="optional">[</span>, <em>safe</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.quote_plus" title="Permalink to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#urllib.quote" title="urllib.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote()</span></code></a>, but also replaces spaces by plus signs, as required for quoting HTML form values when building up a query string to go into a URL. Plus signs in the original string are escaped unless they are included in <em>safe</em>. It also does not have <em>safe</em> default to <code class="docutils literal notranslate"><span class="pre">'/'</span></code>.</p> </dd></dl> <dl class="function"> <dt id="urllib.unquote"> <code class="descclassname">urllib.</code><code class="descname">unquote</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.unquote" title="Permalink to this definition">¶</a></dt> <dd><p>Replace <code class="docutils literal notranslate"><span class="pre">%xx</span></code> escapes by their single-character equivalent.</p> <p>Example: <code class="docutils literal notranslate"><span class="pre">unquote('/%7Econnolly/')</span></code> yields <code class="docutils literal notranslate"><span class="pre">'/~connolly/'</span></code>.</p> </dd></dl> <dl class="function"> <dt id="urllib.unquote_plus"> <code class="descclassname">urllib.</code><code class="descname">unquote_plus</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.unquote_plus" title="Permalink to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#urllib.unquote" title="urllib.unquote"><code class="xref py py-func docutils literal notranslate"><span class="pre">unquote()</span></code></a>, but also replaces plus signs by spaces, as required for unquoting HTML form values.</p> </dd></dl> <dl class="function"> <dt id="urllib.urlencode"> <code class="descclassname">urllib.</code><code class="descname">urlencode</code><span class="sig-paren">(</span><em>query</em><span class="optional">[</span>, <em>doseq</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.urlencode" title="Permalink to this definition">¶</a></dt> <dd><p>Convert a mapping object or a sequence of two-element tuples to a “percent-encoded” string, suitable to pass to <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> above as the optional <em>data</em> argument. This is useful to pass a dictionary of form fields to a <code class="docutils literal notranslate"><span class="pre">POST</span></code> request. The resulting string is a series of <code class="docutils literal notranslate"><span class="pre">key=value</span></code> pairs separated by <code class="docutils literal notranslate"><span class="pre">'&'</span></code> characters, where both <em>key</em> and <em>value</em> are quoted using <a class="reference internal" href="#urllib.quote_plus" title="urllib.quote_plus"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote_plus()</span></code></a> above. When a sequence of two-element tuples is used as the <em>query</em> argument, the first element of each tuple is a key and the second is a value. The value element in itself can be a sequence and in that case, if the optional parameter <em>doseq</em> is evaluates to <code class="docutils literal notranslate"><span class="pre">True</span></code>, individual <code class="docutils literal notranslate"><span class="pre">key=value</span></code> pairs separated by <code class="docutils literal notranslate"><span class="pre">'&'</span></code> are generated for each element of the value sequence for the key. The order of parameters in the encoded string will match the order of parameter tuples in the sequence. The <a class="reference internal" href="urlparse.html#module-urlparse" title="urlparse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urlparse</span></code></a> module provides the functions <code class="xref py py-func docutils literal notranslate"><span class="pre">parse_qs()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">parse_qsl()</span></code> which are used to parse query strings into Python data structures.</p> </dd></dl> <dl class="function"> <dt id="urllib.pathname2url"> <code class="descclassname">urllib.</code><code class="descname">pathname2url</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.pathname2url" title="Permalink to this definition">¶</a></dt> <dd><p>Convert the pathname <em>path</em> from the local syntax for a path to the form used in the path component of a URL. This does not produce a complete URL. The return value will already be quoted using the <a class="reference internal" href="#urllib.quote" title="urllib.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote()</span></code></a> function.</p> </dd></dl> <dl class="function"> <dt id="urllib.url2pathname"> <code class="descclassname">urllib.</code><code class="descname">url2pathname</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.url2pathname" title="Permalink to this definition">¶</a></dt> <dd><p>Convert the path component <em>path</em> from a percent-encoded URL to the local syntax for a path. This does not accept a complete URL. This function uses <a class="reference internal" href="#urllib.unquote" title="urllib.unquote"><code class="xref py py-func docutils literal notranslate"><span class="pre">unquote()</span></code></a> to decode <em>path</em>.</p> </dd></dl> <dl class="function"> <dt id="urllib.getproxies"> <code class="descclassname">urllib.</code><code class="descname">getproxies</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.getproxies" title="Permalink to this definition">¶</a></dt> <dd><p>This helper function returns a dictionary of scheme to proxy server URL mappings. It scans the environment for variables named <code class="docutils literal notranslate"><span class="pre"><scheme>_proxy</span></code>, in case insensitive way, for all operating systems first, and when it cannot find it, looks for proxy information from Mac OSX System Configuration for Mac OS X and Windows Systems Registry for Windows. If both lowercase and uppercase environment variables exist (and disagree), lowercase is preferred.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">If the environment variable <code class="docutils literal notranslate"><span class="pre">REQUEST_METHOD</span></code> is set, which usually indicates your script is running in a CGI environment, the environment variable <code class="docutils literal notranslate"><span class="pre">HTTP_PROXY</span></code> (uppercase <code class="docutils literal notranslate"><span class="pre">_PROXY</span></code>) will be ignored. This is because that variable can be injected by a client using the “Proxy:” HTTP header. If you need to use an HTTP proxy in a CGI environment, either use <code class="docutils literal notranslate"><span class="pre">ProxyHandler</span></code> explicitly, or make sure the variable name is in lowercase (or at least the <code class="docutils literal notranslate"><span class="pre">_proxy</span></code> suffix).</p> </div> </dd></dl> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">urllib also exposes certain utility functions like splittype, splithost and others parsing URL into various components. But it is recommended to use <a class="reference internal" href="urlparse.html#module-urlparse" title="urlparse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urlparse</span></code></a> for parsing URLs rather than using these functions directly. Python 3 does not expose these helper functions from <code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code> module.</p> </div> </div> <div class="section" id="url-opener-objects"> <h2>20.5.3. URL Opener objects<a class="headerlink" href="#url-opener-objects" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="urllib.URLopener"> <em class="property">class </em><code class="descclassname">urllib.</code><code class="descname">URLopener</code><span class="sig-paren">(</span><span class="optional">[</span><em>proxies</em><span class="optional">[</span>, <em>context</em><span class="optional">[</span>, <em>**x509</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.URLopener" title="Permalink to this definition">¶</a></dt> <dd><p>Base class for opening and reading URLs. Unless you need to support opening objects using schemes other than <code class="file docutils literal notranslate"><span class="pre">http:</span></code>, <code class="file docutils literal notranslate"><span class="pre">ftp:</span></code>, or <code class="file docutils literal notranslate"><span class="pre">file:</span></code>, you probably want to use <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a>.</p> <p>By default, the <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> class sends a <em class="mailheader">User-Agent</em> header of <code class="docutils literal notranslate"><span class="pre">urllib/VVV</span></code>, where <em>VVV</em> is the <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> version number. Applications can define their own <em class="mailheader">User-Agent</em> header by subclassing <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> or <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> and setting the class attribute <a class="reference internal" href="#urllib.URLopener.version" title="urllib.URLopener.version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">version</span></code></a> to an appropriate string value in the subclass definition.</p> <p>The optional <em>proxies</em> parameter should be a dictionary mapping scheme names to proxy URLs, where an empty dictionary turns proxies off completely. Its default value is <code class="docutils literal notranslate"><span class="pre">None</span></code>, in which case environmental proxy settings will be used if present, as discussed in the definition of <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a>, above.</p> <p>The <em>context</em> parameter may be a <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance. If given, it defines the SSL settings the opener uses to make HTTPS connections.</p> <p>Additional keyword parameters, collected in <em>x509</em>, may be used for authentication of the client when using the <code class="file docutils literal notranslate"><span class="pre">https:</span></code> scheme. The keywords <em>key_file</em> and <em>cert_file</em> are supported to provide an SSL key and certificate; both are needed to support client authentication.</p> <p><a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> objects will raise an <a class="reference internal" href="exceptions.html#exceptions.IOError" title="exceptions.IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a> exception if the server returns an error code.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 2.7.9: </span>The <em>context</em> parameter was added. All the neccessary certificate and hostname checks are done by default.</p> </div> <dl class="method"> <dt id="urllib.URLopener.open"> <code class="descname">open</code><span class="sig-paren">(</span><em>fullurl</em><span class="optional">[</span>, <em>data</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.URLopener.open" title="Permalink to this definition">¶</a></dt> <dd><p>Open <em>fullurl</em> using the appropriate protocol. This method sets up cache and proxy information, then calls the appropriate open method with its input arguments. If the scheme is not recognized, <a class="reference internal" href="#urllib.URLopener.open_unknown" title="urllib.URLopener.open_unknown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_unknown()</span></code></a> is called. The <em>data</em> argument has the same meaning as the <em>data</em> argument of <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a>.</p> </dd></dl> <dl class="method"> <dt id="urllib.URLopener.open_unknown"> <code class="descname">open_unknown</code><span class="sig-paren">(</span><em>fullurl</em><span class="optional">[</span>, <em>data</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.URLopener.open_unknown" title="Permalink to this definition">¶</a></dt> <dd><p>Overridable interface to open unknown URL types.</p> </dd></dl> <dl class="method"> <dt id="urllib.URLopener.retrieve"> <code class="descname">retrieve</code><span class="sig-paren">(</span><em>url</em><span class="optional">[</span>, <em>filename</em><span class="optional">[</span>, <em>reporthook</em><span class="optional">[</span>, <em>data</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.URLopener.retrieve" title="Permalink to this definition">¶</a></dt> <dd><p>Retrieves the contents of <em>url</em> and places it in <em>filename</em>. The return value is a tuple consisting of a local filename and either a <a class="reference internal" href="mimetools.html#mimetools.Message" title="mimetools.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">mimetools.Message</span></code></a> object containing the response headers (for remote URLs) or <code class="docutils literal notranslate"><span class="pre">None</span></code> (for local URLs). The caller must then open and read the contents of <em>filename</em>. If <em>filename</em> is not given and the URL refers to a local file, the input filename is returned. If the URL is non-local and <em>filename</em> is not given, the filename is the output of <a class="reference internal" href="tempfile.html#tempfile.mktemp" title="tempfile.mktemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mktemp()</span></code></a> with a suffix that matches the suffix of the last path component of the input URL. If <em>reporthook</em> is given, it must be a function accepting three numeric parameters. It will be called after each chunk of data is read from the network. <em>reporthook</em> is ignored for local URLs.</p> <p>If the <em>url</em> uses the <code class="file docutils literal notranslate"><span class="pre">http:</span></code> scheme identifier, the optional <em>data</em> argument may be given to specify a <code class="docutils literal notranslate"><span class="pre">POST</span></code> request (normally the request type is <code class="docutils literal notranslate"><span class="pre">GET</span></code>). The <em>data</em> argument must in standard <em class="mimetype">application/x-www-form-urlencoded</em> format; see the <a class="reference internal" href="#urllib.urlencode" title="urllib.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlencode()</span></code></a> function below.</p> </dd></dl> <dl class="attribute"> <dt id="urllib.URLopener.version"> <code class="descname">version</code><a class="headerlink" href="#urllib.URLopener.version" title="Permalink to this definition">¶</a></dt> <dd><p>Variable that specifies the user agent of the opener object. To get <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> to tell servers that it is a particular user agent, set this in a subclass as a class variable or in the constructor before calling the base constructor.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="urllib.FancyURLopener"> <em class="property">class </em><code class="descclassname">urllib.</code><code class="descname">FancyURLopener</code><span class="sig-paren">(</span><em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.FancyURLopener" title="Permalink to this definition">¶</a></dt> <dd><p><a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> subclasses <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> providing default handling for the following HTTP response codes: 301, 302, 303, 307 and 401. For the 30x response codes listed above, the <em class="mailheader">Location</em> header is used to fetch the actual URL. For 401 response codes (authentication required), basic HTTP authentication is performed. For the 30x response codes, recursion is bounded by the value of the <em>maxtries</em> attribute, which defaults to 10.</p> <p>For all other response codes, the method <code class="xref py py-meth docutils literal notranslate"><span class="pre">http_error_default()</span></code> is called which you can override in subclasses to handle the error appropriately.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">According to the letter of <span class="target" id="index-7"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a>, 301 and 302 responses to POST requests must not be automatically redirected without confirmation by the user. In reality, browsers do allow automatic redirection of these responses, changing the POST to a GET, and <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> reproduces this behaviour.</p> </div> <p>The parameters to the constructor are the same as those for <a class="reference internal" href="#urllib.URLopener" title="urllib.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a>.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">When performing basic authentication, a <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> instance calls its <a class="reference internal" href="#urllib.FancyURLopener.prompt_user_passwd" title="urllib.FancyURLopener.prompt_user_passwd"><code class="xref py py-meth docutils literal notranslate"><span class="pre">prompt_user_passwd()</span></code></a> method. The default implementation asks the users for the required information on the controlling terminal. A subclass may override this method to support more appropriate behavior if needed.</p> </div> <p>The <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> class offers one additional method that should be overloaded to provide the appropriate behavior:</p> <dl class="method"> <dt id="urllib.FancyURLopener.prompt_user_passwd"> <code class="descname">prompt_user_passwd</code><span class="sig-paren">(</span><em>host</em>, <em>realm</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.FancyURLopener.prompt_user_passwd" title="Permalink to this definition">¶</a></dt> <dd><p>Return information needed to authenticate the user at the given host in the specified security realm. The return value should be a tuple, <code class="docutils literal notranslate"><span class="pre">(user,</span> <span class="pre">password)</span></code>, which can be used for basic authentication.</p> <p>The implementation prompts for this information on the terminal; an application should override this method to use an appropriate interaction model in the local environment.</p> </dd></dl> </dd></dl> <dl class="exception"> <dt id="urllib.ContentTooShortError"> <em class="property">exception </em><code class="descclassname">urllib.</code><code class="descname">ContentTooShortError</code><span class="sig-paren">(</span><em>msg</em><span class="optional">[</span>, <em>content</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#urllib.ContentTooShortError" title="Permalink to this definition">¶</a></dt> <dd><p>This exception is raised when the <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> function detects that the amount of the downloaded data is less than the expected amount (given by the <em>Content-Length</em> header). The <code class="xref py py-attr docutils literal notranslate"><span class="pre">content</span></code> attribute stores the downloaded (and supposedly truncated) data.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.5.</span></p> </div> </dd></dl> </div> <div class="section" id="urllib-restrictions"> <h2>20.5.4. <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> Restrictions<a class="headerlink" href="#urllib-restrictions" title="Permalink to this headline">¶</a></h2> <blockquote> <div></div></blockquote> <ul id="index-8"> <li><p class="first">Currently, only the following protocols are supported: HTTP, (versions 0.9 and 1.0), FTP, and local files.</p> </li> <li><p class="first">The caching feature of <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> has been disabled until I find the time to hack proper processing of Expiration time headers.</p> </li> <li><p class="first">There should be a function to query whether a particular URL is in the cache.</p> </li> <li><p class="first">For backward compatibility, if a URL appears to point to a local file but the file can’t be opened, the URL is re-interpreted using the FTP protocol. This can sometimes cause confusing error messages.</p> </li> <li><p class="first">The <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> and <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> functions can cause arbitrarily long delays while waiting for a network connection to be set up. This means that it is difficult to build an interactive Web client using these functions without using threads.</p> </li> <li id="index-9"><p class="first">The data returned by <a class="reference internal" href="#urllib.urlopen" title="urllib.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> or <a class="reference internal" href="#urllib.urlretrieve" title="urllib.urlretrieve"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlretrieve()</span></code></a> is the raw data returned by the server. This may be binary data (such as an image), plain text or (for example) HTML. The HTTP protocol provides type information in the reply header, which can be inspected by looking at the <em class="mailheader">Content-Type</em> header. If the returned data is HTML, you can use the module <a class="reference internal" href="htmllib.html#module-htmllib" title="htmllib: A parser for HTML documents. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">htmllib</span></code></a> to parse it.</p> </li> <li id="index-10"><p class="first">The code handling the FTP protocol cannot differentiate between a file and a directory. This can lead to unexpected behavior when attempting to read a URL that points to a file that is not accessible. If the URL ends in a <code class="docutils literal notranslate"><span class="pre">/</span></code>, it is assumed to refer to a directory and will be handled accordingly. But if an attempt to read a file leads to a 550 error (meaning the URL cannot be found or is not accessible, often for permission reasons), then the path is treated as a directory in order to handle the case when a directory is specified by a URL but the trailing <code class="docutils literal notranslate"><span class="pre">/</span></code> has been left off. This can cause misleading results when you try to fetch a file whose read permissions make it inaccessible; the FTP code will try to read it, fail with a 550 error, and then perform a directory listing for the unreadable file. If fine-grained control is needed, consider using the <a class="reference internal" href="ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a> module, subclassing <a class="reference internal" href="#urllib.FancyURLopener" title="urllib.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a>, or changing <em>_urlopener</em> to meet your needs.</p> </li> <li><p class="first">This module does not support the use of proxies which require authentication. This may be implemented in the future.</p> </li> <li id="index-11"><p class="first">Although the <a class="reference internal" href="#module-urllib" title="urllib: Open an arbitrary network resource by URL (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a> module contains (undocumented) routines to parse and unparse URL strings, the recommended interface for URL manipulation is in module <a class="reference internal" href="urlparse.html#module-urlparse" title="urlparse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urlparse</span></code></a>.</p> </li> </ul> </div> <div class="section" id="examples"> <span id="urllib-examples"></span><h2>20.5.5. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2> <p>Here is an example session that uses the <code class="docutils literal notranslate"><span class="pre">GET</span></code> method to retrieve a URL containing parameters:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">urllib</span> <span class="gp">>>> </span><span class="n">params</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">({</span><span class="s1">'spam'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'eggs'</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">'bacon'</span><span class="p">:</span> <span class="mi">0</span><span class="p">})</span> <span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">"http://www.musi-cal.com/cgi-bin/query?</span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">params</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">print</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </pre></div> </div> <p>The following example uses the <code class="docutils literal notranslate"><span class="pre">POST</span></code> method instead:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">urllib</span> <span class="gp">>>> </span><span class="n">params</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">({</span><span class="s1">'spam'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'eggs'</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">'bacon'</span><span class="p">:</span> <span class="mi">0</span><span class="p">})</span> <span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">"http://www.musi-cal.com/cgi-bin/query"</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">print</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </pre></div> </div> <p>The following example uses an explicitly specified HTTP proxy, overriding environment settings:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">urllib</span> <span class="gp">>>> </span><span class="n">proxies</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'http'</span><span class="p">:</span> <span class="s1">'http://proxy.example.com:8080/'</span><span class="p">}</span> <span class="gp">>>> </span><span class="n">opener</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">FancyURLopener</span><span class="p">(</span><span class="n">proxies</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">opener</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"http://www.python.org"</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </pre></div> </div> <p>The following example uses no proxies at all, overriding environment settings:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">urllib</span> <span class="gp">>>> </span><span class="n">opener</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">FancyURLopener</span><span class="p">({})</span> <span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">opener</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"http://www.python.org/"</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </pre></div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">20.5. <code class="docutils literal notranslate"><span class="pre">urllib</span></code> — Open arbitrary resources by URL</a><ul> <li><a class="reference internal" href="#high-level-interface">20.5.1. High-level interface</a></li> <li><a class="reference internal" href="#utility-functions">20.5.2. Utility functions</a></li> <li><a class="reference internal" href="#url-opener-objects">20.5.3. URL Opener objects</a></li> <li><a class="reference internal" href="#urllib-restrictions">20.5.4. <code class="docutils literal notranslate"><span class="pre">urllib</span></code> Restrictions</a></li> <li><a class="reference internal" href="#examples">20.5.5. Examples</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="wsgiref.html" title="previous chapter">20.4. <code class="docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a></p> <h4>Next topic</h4> <p class="topless"><a href="urllib2.html" title="next chapter">20.6. <code class="docutils literal notranslate"><span class="pre">urllib2</span></code> — extensible library for opening URLs</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/library/urllib.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="urllib2.html" title="20.6. urllib2 — extensible library for opening URLs" >next</a> |</li> <li class="right" > <a href="wsgiref.html" title="20.4. wsgiref — WSGI Utilities and Reference Implementation" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.16 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="internet.html" >20. Internet Protocols and Support</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Mar 27, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run