473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Firefox bug in webbrowser module on Ubuntu?!

Hi,

During optimizing SPE for Ubuntu, I found something strange. I have
Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not
working:
import webbrowser
webbrowser.open("http://www.python.org")
It does not throw an exception, but is not able to launch a browser.

Ubuntu ships with Firefox as its default browser, but it looks like it
is not recognized by the standard webbrowser module, instead it seems
to prefer Netscape, which is not installed:
import webbrowser
webbrowser.browser 'netscape'

In the _browsers attribute there seems to be an entry for
'mozilla-firefox', but doesn't seem to work webbrowser._browsers {'galeon': [None, <webbrowser.Galeon instance at 0xb7d261cc>],
'mozilla': [None, <webbrowser.Netscape instance at 0xb7d2608c>],
'mozilla-firefox': [None, <webbrowser.Netscape instance at
0xb7d2612c>], 'w3m': [None, <webbrowser.GenericBrowser instance at
0xb7d22fec>]}

The tryorder is... webbrowser._tryorder

['galeon', 'mozilla-firefox', 'mozilla', 'w3m']

As a workaround I check for the file '/usr/bin/firefox' and use a
os.system call. Of course a user could maybe install Netscape, but it
would be absurd that SPE would require Netscape.

Is there a reason why this doesn't work? It looks like a bug.

Stani
--
http://pythonide.stani.be

Jan 20 '06 #1
5 3094
SPE - Stani's Python Editor wrote:

During optimizing SPE for Ubuntu, I found something strange. I have
Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not
working:
import webbrowser
webbrowser.open("http://www.python.org")


It does not throw an exception, but is not able to launch a browser.


My opinion is that the webbrowser module is fairly obsolete, and that
on modern desktop environments one should use whichever mechanism that
is provided by such environments to open URLs instead. Consequently, I
made a package available for the purpose of performing such operations:

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

There are certain ways to override the autodetection in use within that
module, and a DESKTOP_LAUNCH environment variable can also be set to
configure its behaviour further. Unfortunately, attempts to confirm the
standardisation status of that variable failed to cut through the turf
wars, newbie-bashing and MIME type hair-splitting on the xdg mailing
list, but a Google search seemed to suggest that my application of it
isn't inappropriate.

Paul

Jan 20 '06 #2
ncf
This section is the cause of the problem:

for browser in ("mozilla-firefox", "mozilla-firebird",
"mozilla", "netscape"):
if _iscommand(browser):
register(browser, None, Netscape(browser))

It's trying to load "mozilla-firefox" as the exec name instead of
simply "firefox".

A potential workaround *might* be to do this:

import webbrowser
if webbrowser._iscommand("firefox"):
webbrowser.register("firefox", None, Netscape("firefox"))
webbrowser.open("http://www.google.com/")

((Untested))

Best of luck
SPE - Stani's Python Editor wrote:
Hi,

During optimizing SPE for Ubuntu, I found something strange. I have
Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not
working:
import webbrowser
webbrowser.open("http://www.python.org")
It does not throw an exception, but is not able to launch a browser.

Ubuntu ships with Firefox as its default browser, but it looks like it
is not recognized by the standard webbrowser module, instead it seems
to prefer Netscape, which is not installed:
import webbrowser
webbrowser.browser 'netscape'

In the _browsers attribute there seems to be an entry for
'mozilla-firefox', but doesn't seem to work webbrowser._browsers {'galeon': [None, <webbrowser.Galeon instance at 0xb7d261cc>],
'mozilla': [None, <webbrowser.Netscape instance at 0xb7d2608c>],
'mozilla-firefox': [None, <webbrowser.Netscape instance at
0xb7d2612c>], 'w3m': [None, <webbrowser.GenericBrowser instance at
0xb7d22fec>]}

The tryorder is... webbrowser._tryorder

['galeon', 'mozilla-firefox', 'mozilla', 'w3m']

As a workaround I check for the file '/usr/bin/firefox' and use a
os.system call. Of course a user could maybe install Netscape, but it
would be absurd that SPE would require Netscape.

Is there a reason why this doesn't work? It looks like a bug.

Stani
--
http://pythonide.stani.be


Jan 21 '06 #3

ncf> This section is the cause of the problem:
ncf> for browser in ("mozilla-firefox", "mozilla-firebird",
ncf> "mozilla", "netscape"):
ncf> if _iscommand(browser):
ncf> register(browser, None, Netscape(browser))

In SVN trunk (aka 2.5a0) this code is

for browser in ("mozilla-firefox", "firefox",
"mozilla-firebird", "firebird",
"mozilla", "netscape"):
if _iscommand(browser):
register(browser, None, Mozilla(browser))

where Mozilla == Netscape, so your proposed fix appears to be correct.
(Which reminds me, I have a patch to webbrowser.py to test...)

Skip
Jan 21 '06 #4
This seems ok...
import webbrowser
webbrowser._iscommand("firefox") True webbrowser.register("firefox",None,webbrowser.Nets cape("firefox"))
webbrowser._browsers {'galeon': [None, <webbrowser.Galeon instance at 0xb7d471cc>],
'firefox': [None, <webbrowser.Netscape instance at 0xb7d43bcc>],
'mozilla': [None, <webbrowser.Netscape instance at 0xb7d4708c>],
'mozilla-firefox': [None, <webbrowser.Netscape instance at
0xb7d4712c>], 'w3m': [None, <webbrowser.GenericBrowser instance at
0xb7d43fec>]}

But it is still not working... webbrowser.open("http://www.python.org") ....doesn't do anything

However... import os
os.path.exists('/usr/bin/firefox')

True

I also have Ubuntu on a VMware Player and there it works out of the
box, although firefox is not registered there. (mozilla-firefox is.)

It is strange as I just installed Ubuntu on this system and can't
imagine something is screwed up already.

Jan 22 '06 #5
Paul Boddie napisał(a):
There are certain ways to override the autodetection in use within that
module, and a DESKTOP_LAUNCH environment variable can also be set to
configure its behaviour further. Unfortunately, attempts to confirm the
standardisation status of that variable failed to cut through the turf
wars, newbie-bashing and MIME type hair-splitting on the xdg mailing
list, but a Google search seemed to suggest that my application of it
isn't inappropriate.


As this isn't yet actual standard but proposed only, I decided to give
my users ability to select preferred way to "open" media files, so even
running some exotic desktop (Fluxbox and FVWM are very popular choices
here) they can open urls from my application using either kfmclient,
gnome-open or custom defined command.

--
Jarek Zgoda
http://jpa.berlios.de/
Jan 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthias Huening | last post by:
Hi, os.startfile('http://www.python.org') works fine on WinXP with IE as default webbrowser. With Mozilla Firefox 0.9 as default webbrowser, however, I get an error. Firefox starts, the page...
19
by: Blair P. Houghton | last post by:
I'm just learning Python, so bear with. I was messing around with the webbrowser module and decided it was pretty cool to have the browser open a URL from within a python script, so I wrote a...
8
by: Dustan | last post by:
At http://docs.python.org/whatsnew/modules.html on the webbrowser module, it says "A number of additional browsers were added to the supported list such as Firefox, Opera, Konqueror, and elinks." ...
11
by: davecph | last post by:
I'm constructing a website with a layout created with div-tags. They have a fixed width, float left, and display inline. When one of the div's contain a select-element the right-most div floats down...
0
by: Norman Lorrain | last post by:
I don't have a Vista machine to test this on, but I have users reporting a problem with the following e.g. import webbrowser webbrowser.open('http://www.google.com') File "webbrowser.pyc",...
0
by: BartlebyScrivener | last post by:
Hello, On Debian Etch, when I use the webbrowser.open module to launch firefox with a url, it opens UNDER gnome terminal in the background. If I just launch firefox from the commandline, it...
0
by: Dotan Cohen | last post by:
Where can I find a wx module for Python? I'm trying to run taskcoach, but I cannot find this package. Thanks. ubuntu@ubuntu-laptop:~/Desktop/todo-manager-0.75.1/todo-manager-0.75.1$ taskcoach.py...
2
by: krishnakant Mane | last post by:
hello all, as I posted in my previous thread, I am generating html reports for my client software. I am yet to find a satisfactory module which can help me actually create headings, bold and...
0
by: Lie | last post by:
Yesterday I installed compiz-icon in my Ubuntu. Today, when I go to the python interpreter, I happen to do this: ### START OF PYTHON SESSION ### Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.