diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-10-04 22:00:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-10-04 22:00:42 (GMT) |
commit | e5384b08861edde56d0b280f5993766d309ab4d0 (patch) | |
tree | eb00d3d112d67d3300bbf23dec974c6994be07ea /Doc/howto/urllib2.rst | |
parent | 7d8d9a588c497c627b62bd7fa79bc6fef693aa5f (diff) | |
download | cpython-e5384b08861edde56d0b280f5993766d309ab4d0.zip cpython-e5384b08861edde56d0b280f5993766d309ab4d0.tar.gz cpython-e5384b08861edde56d0b280f5993766d309ab4d0.tar.bz2 |
Merged revisions 66670,66681,66688,66696-66699 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66670 | georg.brandl | 2008-09-28 15:01:36 -0500 (Sun, 28 Sep 2008) | 2 lines
Don't show version in title.
........
r66681 | georg.brandl | 2008-09-29 11:51:35 -0500 (Mon, 29 Sep 2008) | 2 lines
Update nasm location.
........
r66688 | jesse.noller | 2008-09-29 19:15:45 -0500 (Mon, 29 Sep 2008) | 2 lines
issue3770: if SEM_OPEN is 0, disable the mp.synchronize module, rev. Nick Coghlan, Damien Miller
........
r66696 | andrew.kuchling | 2008-09-30 07:31:07 -0500 (Tue, 30 Sep 2008) | 1 line
Edits, and add markup
........
r66697 | andrew.kuchling | 2008-09-30 08:00:34 -0500 (Tue, 30 Sep 2008) | 1 line
Markup fix
........
r66698 | andrew.kuchling | 2008-09-30 08:00:51 -0500 (Tue, 30 Sep 2008) | 1 line
Markup fixes
........
r66699 | andrew.kuchling | 2008-09-30 08:01:46 -0500 (Tue, 30 Sep 2008) | 1 line
Markup fixes. (optparse.rst probably needs an entire revision pass.)
........
Diffstat (limited to 'Doc/howto/urllib2.rst')
-rw-r--r-- | Doc/howto/urllib2.rst | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst index 5d32d4a..d74729b 100644 --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -182,11 +182,12 @@ which comes after we have a look at what happens when things go wrong. Handling Exceptions =================== -*urlopen* raises ``URLError`` when it cannot handle a response (though as usual -with Python APIs, builtin exceptions such as ValueError, TypeError etc. may also +*urlopen* raises :exc:`URLError` when it cannot handle a response (though as usual +with Python APIs, builtin exceptions such as +:exc:`ValueError`, :exc:`TypeError` etc. may also be raised). -``HTTPError`` is the subclass of ``URLError`` raised in the specific case of +:exc:`HTTPError` is the subclass of :exc:`URLError` raised in the specific case of HTTP URLs. The exception classes are exported from the :mod:`urllib.error` module. @@ -217,12 +218,12 @@ the status code indicates that the server is unable to fulfil the request. The default handlers will handle some of these responses for you (for example, if the response is a "redirection" that requests the client fetch the document from a different URL, urllib will handle that for you). For those it can't handle, -urlopen will raise an ``HTTPError``. Typical errors include '404' (page not +urlopen will raise an :exc:`HTTPError`. Typical errors include '404' (page not found), '403' (request forbidden), and '401' (authentication required). See section 10 of RFC 2616 for a reference on all the HTTP error codes. -The ``HTTPError`` instance raised will have an integer 'code' attribute, which +The :exc:`HTTPError` instance raised will have an integer 'code' attribute, which corresponds to the error sent by the server. Error Codes @@ -305,7 +306,7 @@ dictionary is reproduced here for convenience :: } When an error is raised the server responds by returning an HTTP error code -*and* an error page. You can use the ``HTTPError`` instance as a response on the +*and* an error page. You can use the :exc:`HTTPError` instance as a response on the page returned. This means that as well as the code attribute, it also has read, geturl, and info, methods as returned by the ``urllib.response`` module:: @@ -327,7 +328,7 @@ geturl, and info, methods as returned by the ``urllib.response`` module:: Wrapping it Up -------------- -So if you want to be prepared for ``HTTPError`` *or* ``URLError`` there are two +So if you want to be prepared for :exc:`HTTPError` *or* :exc:`URLError` there are two basic approaches. I prefer the second approach. Number 1 @@ -354,7 +355,7 @@ Number 1 .. note:: The ``except HTTPError`` *must* come first, otherwise ``except URLError`` - will *also* catch an ``HTTPError``. + will *also* catch an :exc:`HTTPError`. Number 2 ~~~~~~~~ @@ -380,9 +381,9 @@ Number 2 info and geturl =============== -The response returned by urlopen (or the ``HTTPError`` instance) has two useful -methods ``info`` and ``geturl`` and is defined in the module -:mod:`urllib.response`. +The response returned by urlopen (or the :exc:`HTTPError` instance) has two +useful methods :meth:`info` and :meth:`geturl` and is defined in the module +:mod:`urllib.response`.. **geturl** - this returns the real URL of the page fetched. This is useful because ``urlopen`` (or the opener object used) may have followed a |