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

MAK mike at mmrd.com
Thu Aug 21 15:37:56 EDT 2003


I'm stumped.

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'".

I've tried variations on the URL, such as "file://c:/mypage.html",
too, without luck.  That one gives me a 'socket.gaierror' exception
with the message "'getaddrinfo failed'".

Upon diving into the code, I found that, in the first case, the third
'/' is left as part of the filename, and in the second case, it ends
up thinking that 'C:' is the hostname of the machine.

Can anyone point out the error of my ways?
Thanks.




More information about the Python-list mailing list