473,505 Members | 14,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

webbrowser module's Firefox support

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

I just installed python 2.5, looking forward to being able to control
firefox without having to make it my default browser, but...

I don't seem to have that functionality. In IDLE:
>>import webbrowser
webbrowser._browsers
{'windows-default': [<class 'webbrowser.WindowsDefault'>, None]}

So I tried to track down what the problem might be, seeing as I also
have Netscape installed on my system (Windows XP), and it's not showing
up either. I found where the code appears to test that the system has
firefox installed, and found it calls _iscommand; here's what I get
running similar code:
>>import os
path = os.environ.get("PATH")
for d in path.split(os.pathsep):
print d

C:\Perl\bin\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
c:\Python22
C:\Program Files\PC-Doctor for Windows\services
C:\Program Files\Hummingbird\Connectivity\7.10\Accessories\
C:\PROGRA~1\CA\SHARED~1\SCANEN~1
C:\PROGRA~1\CA\ETRUST~1

The path for firefox is "C:\Program Files\Mozilla Firefox\firefox.exe".

Ok, now I'm at a roadblock; I have no idea where to go from here.

I did do a search here, but came up empty-handed. Can anyone tell me
how to get the webbrowser module to recognize firefox's existence,
given this information?

Sep 23 '06 #1
8 4611
Dustan wrote:
I did do a search here, but came up empty-handed. Can anyone tell me
how to get the webbrowser module to recognize firefox's existence,
given this information?
Looks like it is checking %PATH% for firefox.exe. Try:
>>import os
os.environ["PATH"] = r"C:\Program Files\Mozilla Firefox;"
import webbrowser
webbrowser._browsers
Regards,
Jordan

Sep 23 '06 #2

MonkeeSage wrote:
Dustan wrote:
I did do a search here, but came up empty-handed. Can anyone tell me
how to get the webbrowser module to recognize firefox's existence,
given this information?

Looks like it is checking %PATH% for firefox.exe. Try:
>import os
os.environ["PATH"] = r"C:\Program Files\Mozilla Firefox;"
import webbrowser
webbrowser._browsers

Regards,
Jordan
Thanks! But I'm still getting an error message:
>>import webbrowser
webbrowser._browsers
{'windows-default': [<class 'webbrowser.WindowsDefault'>, None],
'firefox': [None, <webbrowser.BackgroundBrowser object at 0x00BAC8D0>]}
>>cont=webbrowser._browsers['firefox'][1]
cont
<webbrowser.BackgroundBrowser object at 0x00BAC8D0>
>>cont.open("http://www.google.com")
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
cont.open("http://www.google.com")
File "C:\Python25\lib\webbrowser.py", line 185, in open
p = subprocess.Popen(cmdline, close_fds=True, preexec_fn=setsid)
File "C:\Python25\lib\subprocess.py", line 551, in __init__
raise ValueError("close_fds is not supported on Windows "
ValueError: close_fds is not supported on Windows platforms

Looking in the docs on subprocess.Popopen
(http://docs.python.org/lib/node529.html), it says "If close_fds is
true, all file descriptors except 0, 1 and 2 will be closed before the
child process is executed. (Unix only)". I have to be frank; I have no
idea what this means. What should I do to fix this?

Sep 23 '06 #3
Dustan wrote:
>cont=webbrowser._browsers['firefox'][1]
Why not use the api? cont=webbrowser.get('firefox')
ValueError: close_fds is not supported on Windows platforms

Looking in the docs on subprocess.Popopen
(http://docs.python.org/lib/node529.html), it says "If close_fds is
true, all file descriptors except 0, 1 and 2 will be closed before the
child process is executed. (Unix only)". I have to be frank; I have no
idea what this means. What should I do to fix this?
It just means that on *nix there is an option to close all open file
handles except stdin, out and err before the browser is called. I'm
thinking that mabye get() does an OS check to see how to call
subprocess.Popen, and you effectively bypassed it by using the
lower-level _browsers attribute. But I could be wrong. Try it with
get() and see how that goes.

Regards,
Jordan

Sep 23 '06 #4

MonkeeSage wrote:
Dustan wrote:
>>cont=webbrowser._browsers['firefox'][1]

Why not use the api? cont=webbrowser.get('firefox')
That didn't work either.
ValueError: close_fds is not supported on Windows platforms

Looking in the docs on subprocess.Popopen
(http://docs.python.org/lib/node529.html), it says "If close_fds is
true, all file descriptors except 0, 1 and 2 will be closed before the
child process is executed. (Unix only)". I have to be frank; I have no
idea what this means. What should I do to fix this?

It just means that on *nix there is an option to close all open file
handles except stdin, out and err before the browser is called. I'm
thinking that mabye get() does an OS check to see how to call
subprocess.Popen, and you effectively bypassed it by using the
lower-level _browsers attribute. But I could be wrong. Try it with
get() and see how that goes.

Regards,
Jordan
Another thing: your fix is only temporary. Is there a way to make it
work even after I close IDLE? I changed the command you gave me a bit
so it doesn't get rid of the other paths:

os.environ["PATH"]+=";C:\Program Files\Mozilla Firefox;" # can't
remember the path for firefox right now...

But either way, it ends up going right back to the previous value after
I close IDLE.

Sep 24 '06 #5
Dustan wrote:
That didn't work either.
Well, I'm out of ideas. It's also odd that it was being read as
webbrowser.BackgroundBrowser...whatever that is! It should have been
webbrowser.Mozilla.
Another thing: your fix is only temporary. Is there a way to make it
work even after I close IDLE? I changed the command you gave me a bit
so it doesn't get rid of the other paths:

os.environ["PATH"]+=";C:\Program Files\Mozilla Firefox;" # can't
remember the path for firefox right now...

But either way, it ends up going right back to the previous value after
I close IDLE.
Yeah, sorry about that, I meant to mention that changes to os.environ
only last for the life of the python process. To set / change
environment variables like PATH permanently, check out this page:
http://www.cims.nyu.edu/systems/plat...s/setpath.html

Regards,
Jordan

Sep 24 '06 #6

MonkeeSage wrote:
Dustan wrote:
That didn't work either.

Well, I'm out of ideas. It's also odd that it was being read as
webbrowser.BackgroundBrowser...whatever that is! It should have been
webbrowser.Mozilla.
Thanks anyway; you have helped me tremendously. I'm sure I'll get
somewhere with this...
Another thing: your fix is only temporary. Is there a way to make it
work even after I close IDLE? I changed the command you gave me a bit
so it doesn't get rid of the other paths:

os.environ["PATH"]+=";C:\Program Files\Mozilla Firefox;" # can't
remember the path for firefox right now...

But either way, it ends up going right back to the previous value after
I close IDLE.

Yeah, sorry about that, I meant to mention that changes to os.environ
only last for the life of the python process. To set / change
environment variables like PATH permanently, check out this page:
http://www.cims.nyu.edu/systems/plat...s/setpath.html
Great! Thanks!
Regards,
Jordan
Sep 24 '06 #7
Dustan wrote:
MonkeeSage wrote:
>Dustan wrote:
I did do a search here, but came up empty-handed. Can anyone tell me
how to get the webbrowser module to recognize firefox's existence,
given this information?

Looks like it is checking %PATH% for firefox.exe. Try:
>>import os
os.environ["PATH"] = r"C:\Program Files\Mozilla Firefox;"
import webbrowser
webbrowser._browsers

Regards,
Jordan

Thanks! But I'm still getting an error message:
>>>import webbrowser
webbrowser._browsers
{'windows-default': [<class 'webbrowser.WindowsDefault'>, None],
'firefox': [None, <webbrowser.BackgroundBrowser object at 0x00BAC8D0>]}
>>>cont=webbrowser._browsers['firefox'][1]
cont
<webbrowser.BackgroundBrowser object at 0x00BAC8D0>
>>>cont.open("http://www.google.com")

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
cont.open("http://www.google.com")
File "C:\Python25\lib\webbrowser.py", line 185, in open
p = subprocess.Popen(cmdline, close_fds=True, preexec_fn=setsid)
File "C:\Python25\lib\subprocess.py", line 551, in __init__
raise ValueError("close_fds is not supported on Windows "
ValueError: close_fds is not supported on Windows platforms

Looking in the docs on subprocess.Popopen
(http://docs.python.org/lib/node529.html), it says "If close_fds is
true, all file descriptors except 0, 1 and 2 will be closed before the
child process is executed. (Unix only)". I have to be frank; I have no
idea what this means. What should I do to fix this?
This is a bug, and has now been fixed in SVN. As a workaround, you can
edit the webbrowser.py file and remove the close_fds and preexec_fn arguments
to Popen.

Georg
Sep 24 '06 #8
>
This is a bug, and has now been fixed in SVN. As a workaround, you can
edit the webbrowser.py file and remove the close_fds and preexec_fn arguments
to Popen.

Georg
Finally! It's working. Thank you so much!

Sep 24 '06 #9

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

Similar topics

2
3474
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...
5
3106
by: SPE - Stani's Python Editor | last post by:
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 >>>...
19
2343
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...
4
3734
by: Gregory Bloom | last post by:
I'm running Python 2.5 under Windows. If I fire up IDLE and enter: it works like a champ, opening the page in Firefox. Same thing goes from a Windows cmd shell: it works as advertised. But...
14
2073
by: Ron Adam | last post by:
Is anyone else having problems with the webbrowser module? Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) on linux2 Type "help", "copyright", "credits" or "license" for more...
4
4467
by: kimiraikkonen | last post by:
Hi, Just to test, i placed a simple webbrowser to login a site, this site has no problems and has same error with IE6 SP2 but it's suppressed as well and no problem with Firefox browser, but using...
2
1587
by: scottbvfx | last post by:
Hi, I'm trying to launch a web browser along with an html file with a fragment identifier in its path. I'm using the webbrowser module for this. ie....
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.