webbrowser module's Firefox support

D

Dustan

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:
{'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:
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?
 
D

Dustan

MonkeeSage said:
Dustan said:
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
None] said:
cont=webbrowser._browsers['firefox'][1]
cont

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?
 
M

MonkeeSage

Dustan said:
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
 
D

Dustan

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

Why not use the api? cont=webbrowser.get('firefox')

That didn't work either.
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.
 
M

MonkeeSage

Dustan said:
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/platforms/windows/setpath.html

Regards,
Jordan
 
D

Dustan

MonkeeSage said:
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/platforms/windows/setpath.html

Great! Thanks!
 
G

Georg Brandl

Dustan said:
MonkeeSage said:
Dustan said:
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
None] said:
cont=webbrowser._browsers['firefox'][1]
cont

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
 
D

Dustan

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!
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top