Issue 1668100: urllib2.urlopen() raises OSError instead of URLError (original) (raw)

Created on 2007-02-24 23:20 by jerry.seutter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug_1591774_failing_test_and_bugfix.patch jerry.seutter,2007-02-24 23:20 patch
bug_1591774_failing_test_and_bugfix_v2.patch jerry.seutter,2007-03-12 06:22 patch v2 - against trunk, uncommented other unit tests that now pass
Messages (7)
msg51952 - (view) Author: Jerry Seutter (jerry.seutter) * (Python committer) Date: 2007-02-24 23:20
See bug 1591774. The base problem is that when passing a file:// url into urllib2.urlopen() for a file that doesn't exist, the os.stat() call fails with an OSError exception which is not caught. The documentation for urllib2 states that urlopen() raises a URLError upon error. This bug can also be triggered when fetching a http:// url. A misconfigured webserver can cause urllib2.urlopen to use the FileHandler (see bug report). This patch catches OSError in the FileHandler class and raises it as a URLError. Unit test included.
msg51953 - (view) Author: John J Lee (jjlee) Date: 2007-02-25 17:01
I recall that when I wrote the urllib2 tests there were a fair few cases similar to this -- indeed, this particular one is already marked in the tests with an "XXXX" in test_file(). What do other people think about these -- should they be fixed, or the docs changed?
msg51954 - (view) Author: Jerry Seutter (jerry.seutter) * (Python committer) Date: 2007-02-26 04:12
Sorry, I looked at that commented out section and didn't immediately see what it was for, so ignored it. I'm not sure what the correct behavior would be in this case. Getting a OSError from a http:// url is unsettling. I guess that if I were using the library, I would only want to have to catch one type of exception. Having to catch both URLError and OSError is inconvenient. If I were looking for a file on disk I would use file(), so the only time someone probably uses the file:// url syntax is when the end user is entering the URL. The end user wouldn't distinguish between the two exception types in this case.
msg51955 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-09 18:18
I think it should be fixed to raise URLError.
msg51956 - (view) Author: Jerry Seutter (jerry.seutter) * (Python committer) Date: 2007-03-12 06:22
File Added: bug_1591774_failing_test_and_bugfix_v2.patch
msg51957 - (view) Author: Jerry Seutter (jerry.seutter) * (Python committer) Date: 2007-03-12 06:23
Added patch v2 which is a patch against trunk, and adds in the tests that were commented out (they previously failed).
msg51958 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-13 08:15
Committed in rev. 54326. Not backporting since it raises a different exception now.
History
Date User Action Args
2022-04-11 14:56:22 admin set github: 44611
2007-02-24 23:20:57 jerry.seutter create