Q: urlopen() and "file:///c:/mypage.html" ??

Michael Geary Mike at DeleteThis.Geary.com
Fri Aug 22 10:55:56 CEST 2003

> MAK wrote:
> > I'm trying to use Python 2.3's urllib2.urlopen() to open an HTML
> > file on the local harddrive of my WinXP box.
> >
> > If I were to use, say, Netscape to open this file, I'd specify it as
> > "file:///c:/mypage.html", and it would open it just fine.  But
> > urlopen() won't accept it as a valid URL. I get an OSError
> > exception with the error message "No such file or directory:
> > '\\C:\\mypage.html'".

Joe Francia wrote:
> This works:
> f = urllib2.urlopen(r'file:///c|\mypage.html')
> But, if you're only opening local files, what's wrong with:
> f = file(r'c:/mypage.html', 'r')

Just to add to that, the significant thing in the working example isn't that
it uses backslash instead of forward slash, but that it uses vertical bar
instead of colon. This works just as well:

f = urllib2.urlopen( 'file:///c|/mypage.html' )


More information about the Python-list mailing list