webbrowser.open still gives problem with file://

Greg Couch gregc at cgl.ucsf.edu
Wed Nov 14 20:17:45 CET 2007

"Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> writes:

>En Mon, 12 Nov 2007 16:18:06 -0300, krishnakant Mane  
><researchbase at gmail.com> escribió:

>> some days bac I posted a problem about webbrowser.open() not opening
>> the file on the local machine.
>> I get a few responses and I tryed working it out.
>> I also refered to the cookbook example posted on that thread.
>> I still can't figure out why
>> webbrowser.open("file:///home/krishna/documents/tut.html") does not
>> open the file.
>> as I mentioned earlier the url in the addressbar of mozilla firefox 3
>> alpha is "file:///home/krishna/"/home/krishna/documents/tut.html"
>> which is indeed wrong.

>I can think of two alternatives:
>1) omit the file: protocol, and just use the absolute file path, like  
>2) use this recipe  
><http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347810> which  
>lets you display content inside a browser window without requiring a  
>temporary file.

>Gabriel Genellina

You didn't say which platform you're on.  I found that on older Mac OS X
systems that one needs to give file://localhost/path instead of file:///path
but the localhost version didn't always work on other platforms.  The other
thing you need to do is to use Python 2.5's version of webbrowser.py instead
of the earlier ones.  It's easy to backport and works *much* better.

	Greg Couch
	UCSF Computer Graphics Lab

More information about the Python-list mailing list