This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib2 HOWTO URLError example minor error
Type: Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, MarmiteFox, docs@python, pablogsal
Priority: low Keywords: patch

Created on 2018-01-17 18:00 by MarmiteFox, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5238 merged pablogsal, 2018-01-18 23:46
Messages (5)
msg310201 - (view) Author: (MarmiteFox) Date: 2018-01-17 18:00
In the HOWTO for urllib2 for Python 2, in the Handling Exceptions section, it discusses the URLError exception being raised by urlopen() (https://docs.python.org/2/howto/urllib2.html#urlerror). The code snippet example for this has (I think) a minor error:
the 3rd line reads:
"except URLError as e:"
which I think should be:
"except urllib2.URLError as e:"

The code as given only works if urllib2 had been imported via:
"from urllib2 import *"
The snippet doesn't list the import statements but all the other examples just use "import urllib2" (and obviously "from x import *" is bad practice anyway and wouldn't be encouraged or expected).

I am relatively new to Python, so it's possible it *is* correct and I just implemented it incorrectly. But if not, it would be helpful to correct it (even though it's a very minor error) so that other newbies like me don't come unstuck when using the tutorial.
msg310260 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-01-18 23:49
Thanks for reporting this issue. Indeed, this is an error in the documentation. Notice that this is corrected in Python3 's version:

https://docs.python.org/3.6/howto/urllib2.html#handling-exceptions

I have prepared a Pull Request fixing this. Thanks!
msg310262 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-01-19 00:16
New changeset 8ca036d4716fc86ff42474ba35d3cd32f0188a15 by Mariatta (Pablo Galindo) in branch '2.7':
bpo-32586: Fix code example in urllib2's doc  (GH-5238)
https://github.com/python/cpython/commit/8ca036d4716fc86ff42474ba35d3cd32f0188a15
msg310263 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-01-19 00:19
Thanks!
msg310265 - (view) Author: (MarmiteFox) Date: 2018-01-19 00:43
Thanks for the fix and the tip about cross-checking in Python 3 - will remember that for the future.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76767
2018-01-19 00:43:54MarmiteFoxsetmessages: + msg310265
2018-01-19 00:19:23Mariattasetstatus: open -> closed
resolution: fixed
messages: + msg310263

stage: patch review -> resolved
2018-01-19 00:16:15Mariattasetnosy: + Mariatta
messages: + msg310262
2018-01-18 23:49:56pablogsalsetpriority: normal -> low
nosy: + pablogsal
messages: + msg310260

2018-01-18 23:46:49pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request5084
2018-01-17 18:00:55MarmiteFoxcreate