Patches item #1668100, was opened at 2007-02-24 18:20
Message generated for change (Comment added) made by collinwinter
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.

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

>Comment By: Collin Winter (collinwinter)
Date: 2007-03-09 13:18

Message:
Logged In: YES 
user_id=1344176
Originator: NO

I think it should be fixed to raise URLError.

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

Comment By: Jerry Seutter (jseutter)
Date: 2007-02-25 23:12

Message:
Logged In: YES 
user_id=1727609
Originator: YES

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.



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

Comment By: John J Lee (jjlee)
Date: 2007-02-25 12:01

Message:
Logged In: YES 
user_id=261020
Originator: NO

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?


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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1668100&group_id=5470
_______________________________________________
Patches mailing list
Patches@python.org
http://mail.python.org/mailman/listinfo/patches

Reply via email to