Skip to content

Commit bfd94ab

Browse files
koyuki7whugovk
andauthored
gh-101100: Fix references to URLError and HTTPError in howto/urllib2.rst (#107966)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
1 parent 8898a86 commit bfd94ab

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Doc/howto/urllib2.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ which comes after we have a look at what happens when things go wrong.
194194
Handling Exceptions
195195
===================
196196

197-
*urlopen* raises :exc:`URLError` when it cannot handle a response (though as
197+
*urlopen* raises :exc:`~urllib.error.URLError` when it cannot handle a response (though as
198198
usual with Python APIs, built-in exceptions such as :exc:`ValueError`,
199199
:exc:`TypeError` etc. may also be raised).
200200

201-
:exc:`HTTPError` is the subclass of :exc:`URLError` raised in the specific case of
201+
:exc:`~urllib.error.HTTPError` is the subclass of :exc:`~urllib.error.URLError` raised in the specific case of
202202
HTTP URLs.
203203

204204
The exception classes are exported from the :mod:`urllib.error` module.
@@ -229,12 +229,12 @@ the status code indicates that the server is unable to fulfil the request. The
229229
default handlers will handle some of these responses for you (for example, if
230230
the response is a "redirection" that requests the client fetch the document from
231231
a different URL, urllib will handle that for you). For those it can't handle,
232-
urlopen will raise an :exc:`HTTPError`. Typical errors include '404' (page not
232+
urlopen will raise an :exc:`~urllib.error.HTTPError`. Typical errors include '404' (page not
233233
found), '403' (request forbidden), and '401' (authentication required).
234234

235235
See section 10 of :rfc:`2616` for a reference on all the HTTP error codes.
236236

237-
The :exc:`HTTPError` instance raised will have an integer 'code' attribute, which
237+
The :exc:`~urllib.error.HTTPError` instance raised will have an integer 'code' attribute, which
238238
corresponds to the error sent by the server.
239239

240240
Error Codes
@@ -317,7 +317,7 @@ dictionary is reproduced here for convenience ::
317317
}
318318

319319
When an error is raised the server responds by returning an HTTP error code
320-
*and* an error page. You can use the :exc:`HTTPError` instance as a response on the
320+
*and* an error page. You can use the :exc:`~urllib.error.HTTPError` instance as a response on the
321321
page returned. This means that as well as the code attribute, it also has read,
322322
geturl, and info, methods as returned by the ``urllib.response`` module::
323323

@@ -338,7 +338,7 @@ geturl, and info, methods as returned by the ``urllib.response`` module::
338338
Wrapping it Up
339339
--------------
340340

341-
So if you want to be prepared for :exc:`HTTPError` *or* :exc:`URLError` there are two
341+
So if you want to be prepared for :exc:`~urllib.error.HTTPError` *or* :exc:`~urllib.error.URLError` there are two
342342
basic approaches. I prefer the second approach.
343343

344344
Number 1
@@ -365,7 +365,7 @@ Number 1
365365
.. note::
366366

367367
The ``except HTTPError`` *must* come first, otherwise ``except URLError``
368-
will *also* catch an :exc:`HTTPError`.
368+
will *also* catch an :exc:`~urllib.error.HTTPError`.
369369

370370
Number 2
371371
~~~~~~~~
@@ -391,7 +391,7 @@ Number 2
391391
info and geturl
392392
===============
393393

394-
The response returned by urlopen (or the :exc:`HTTPError` instance) has two
394+
The response returned by urlopen (or the :exc:`~urllib.error.HTTPError` instance) has two
395395
useful methods :meth:`info` and :meth:`geturl` and is defined in the module
396396
:mod:`urllib.response`..
397397

0 commit comments

Comments
 (0)