[Patches] [ python-Patches-1668100 ] urllib2.urlopen() raises OSError instead of URLError

SourceForge.net noreply at sourceforge.net
Sun Feb 25 00:20:57 CET 2007


Patches item #1668100, was opened at 2007-02-24 16:20
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1668100&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jerry Seutter (jseutter)
Assigned to: Nobody/Anonymous (nobody)
Summary: urllib2.urlopen() raises OSError instead of URLError

Initial Comment:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1668100&group_id=5470


More information about the Patches mailing list