By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

webbrowser module's Firefox support

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
>
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 discussion thread is closed

Replies have been disabled for this discussion.