I really need webbrowser.open('file://') to open a web browser

T

Timur Tabi

After reading several web pages and mailing list threads, I've learned
that the webbrowser module does not really support opening local
files, even if I use a file:// URL designator. In most cases,
webbrowser.open() will indeed open the default web browser, but with
Python 2.6 on my Fedora 10 system, it opens a text editor instead. On
Python 2.5, it opens the default web browser.

This is a problem because my Python script creates a local HTML file
and I want it displayed on the web browser.

So is there any way to force webbrowser.open() to always use an actual
web browser?
 
J

Jonathan Temple

After reading several web pages and mailing list threads, I've learned
that the webbrowser module does not really support opening local
files, even if I use a file:// URL designator.  In most cases,
webbrowser.open() will indeed open the default web browser, but with
Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
Python 2.5, it opens the default web browser.

This is a problem because my Python script creates a local HTML file
and I want it displayed on the web browser.

So is there any way to force webbrowser.open() to always use an actual
web browser?

Might not be useful, but trying open_new_tab() on...

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.'gnome-open'

When attempting to use open_new_tab(), I get:

file:///home/jon/blahblah.html - opens in Firefox
file:///home/jon/blahblah.txt - opens in gedit

Jon.
 
J

Jon Clements

After reading several web pages and mailing list threads, I've learned
that the webbrowser module does not really support opening local
files, even if I use a file:// URL designator.  In most cases,
webbrowser.open() will indeed open the default web browser, but with
Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
Python 2.5, it opens the default web browser.
This is a problem because my Python script creates a local HTML file
and I want it displayed on the web browser.
So is there any way to force webbrowser.open() to always use an actual
web browser?

Might not be useful, but trying open_new_tab() on...

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>> import webbrowser as wb
'gnome-open'

When attempting to use open_new_tab(), I get:

file:///home/jon/blahblah.html - opens in Firefox
file:///home/jon/blahblah.txt  - opens in gedit

Jon.

Err, I'd just like to mention that "Jonathan Temple" did not post that
message: He was checking his Google Mail on my machine, and when I
went to send my post, it got a little confused.

Cheers,

Jon.
 
P

Paul Boddie

After reading several web pages and mailing list threads, I've learned
that the webbrowser module does not really support opening local
files, even if I use a file:// URL designator.  In most cases,
webbrowser.open() will indeed open the default web browser, but with
Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
Python 2.5, it opens the default web browser.

The webbrowser module seems to have changed. For example, in the
Python 2.5 standard library, it uses gconftool to query the GNOME
registry and get the preferred browser, whereas in the Python 2.6
standard library, it appears to use gnome-open instead (but only in a
GNOME environment). For KDE, there's a KDE-specific usage of kfmclient
in the 2.6 library. See here for more:

http://svn.python.org/view/python/tags/r254/Lib/webbrowser.py?revision=67917&view=markup
http://svn.python.org/view/python/tags/r264/Lib/webbrowser.py?revision=75707&view=markup
This is a problem because my Python script creates a local HTML file
and I want it displayed on the web browser.

Generally, the desktop-specific tools should know that a browser is
the appropriate application for an HTML file, and testing with both
xdg-open, gnome-open and "kfmclient openURL" seems to open browsers on
HTML files (using file:///...) for me (using KDE, Kubuntu 8.04). Of
course, this depends on the settings in use on your desktop, but it
should be noted that using "kfmclient exec" could have the effect you
describe.
So is there any way to force webbrowser.open() to always use an actual
web browser?

Not that I'm aware of. Sadly, standardisation of applications and
services - having a command which can open a particular class of
application (such as "e-mail reader", "Web browser") - seems to be
absent from the free desktop arena, although I do recall there being a
preferred applications dialogue in KDE, at least. Maybe this
information is exposed somehow, and maybe I'll incorporate such stuff
into the desktop package eventually:

http://pypi.python.org/pypi/desktop

Note that the desktop package concerns itself precisely with opening
files in text editors if that's how the user has configured their
desktop, whereas the webbrowser module should really only use a Web
browser, obviously.

Paul
 
T

Timur Tabi

Generally, the desktop-specific tools should know that a browser is
the appropriate application for an HTML file, and testing with both
xdg-open, gnome-open and "kfmclient openURL" seems to open browsers on
HTML files (using file:///...) for me (using KDE, Kubuntu 8.04). Of
course, this depends on the settings in use on your desktop, but it
should be noted that using "kfmclient exec" could have the effect you
describe.

I'm using Gnome, and I have HTML files associated with Firefox.
However, my default web browser is Seamonkey, and when I do
webbrowser.open('http://...'), it opens that URL in Seamonkey, not
Firefox. So if there is some Gnome association between an .html file
and a text editor, I don't know where it is defined.
Not that I'm aware of. Sadly, standardisation of applications and
services - having a command which can open a particular class of
application (such as "e-mail reader", "Web browser") - seems to be
absent from the free desktop arena, although I do recall there being a
preferred applications dialogue in KDE, at least.

I would be sympathetic to this problem if the API were called
desktop.open(...). But it's called webbrowser.open(), so it has to be
certain that a web browser is being at all times. IMHO, any other
behavior is a bug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top