webbrowser module's Firefox support

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustan

    #1

    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._b rowsers
    {'windows-default': [<class 'webbrowser.Win dowsDefault'>, 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.p athsep):
    print d

    C:\Perl\bin\
    C:\WINDOWS\syst em32
    C:\WINDOWS
    C:\WINDOWS\Syst em32\Wbem
    c:\Python22
    C:\Program Files\PC-Doctor for Windows\service s
    C:\Program Files\Hummingbi rd\Connectivity \7.10\Accessori es\
    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?

  • MonkeeSage

    #2
    Re: webbrowser module's Firefox support

    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._b rowsers
    Regards,
    Jordan

    Comment

    • Dustan

      #3
      Re: webbrowser module's Firefox support


      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._br owsers
      >
      Regards,
      Jordan
      Thanks! But I'm still getting an error message:
      >>import webbrowser
      >>webbrowser._b rowsers
      {'windows-default': [<class 'webbrowser.Win dowsDefault'>, None],
      'firefox': [None, <webbrowser.Bac kgroundBrowser object at 0x00BAC8D0>]}
      >>cont=webbrows er._browsers['firefox'][1]
      >>cont
      <webbrowser.Bac kgroundBrowser object at 0x00BAC8D0>
      >>cont.open("ht tp://www.google.com" )
      Traceback (most recent call last):
      File "<pyshell#1 0>", line 1, in <module>
      cont.open("http ://www.google.com" )
      File "C:\Python25\li b\webbrowser.py ", line 185, in open
      p = subprocess.Pope n(cmdline, close_fds=True, preexec_fn=sets id)
      File "C:\Python25\li b\subprocess.py ", line 551, in __init__
      raise ValueError("clo se_fds is not supported on Windows "
      ValueError: close_fds is not supported on Windows platforms

      Looking in the docs on subprocess.Popo pen
      (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?

      Comment

      • MonkeeSage

        #4
        Re: webbrowser module's Firefox support

        Dustan wrote:
        >cont=webbrowse r._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.Popo pen
        (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.Pope n, 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

        Comment

        • Dustan

          #5
          Re: webbrowser module's Firefox support


          MonkeeSage wrote:
          Dustan wrote:
          >>cont=webbrows er._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.Popo pen
          (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.Pope n, 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:\Progra m 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.

          Comment

          • MonkeeSage

            #6
            Re: webbrowser module's Firefox support

            Dustan wrote:
            That didn't work either.
            Well, I'm out of ideas. It's also odd that it was being read as
            webbrowser.Back groundBrowser.. .whatever that is! It should have been
            webbrowser.Mozi lla.
            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:\Progra m 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:


            Regards,
            Jordan

            Comment

            • Dustan

              #7
              Re: webbrowser module's Firefox support


              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.Back groundBrowser.. .whatever that is! It should have been
              webbrowser.Mozi lla.
              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:\Progra m 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

              Comment

              • Georg Brandl

                #8
                Re: webbrowser module's Firefox support

                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._b rowsers
                >>
                >Regards,
                >Jordan
                >
                Thanks! But I'm still getting an error message:
                >
                >>>import webbrowser
                >>>webbrowser._ browsers
                {'windows-default': [<class 'webbrowser.Win dowsDefault'>, None],
                'firefox': [None, <webbrowser.Bac kgroundBrowser object at 0x00BAC8D0>]}
                >>>cont=webbrow ser._browsers['firefox'][1]
                >>>cont
                <webbrowser.Bac kgroundBrowser object at 0x00BAC8D0>
                >>>cont.open("h ttp://www.google.com" )
                >
                Traceback (most recent call last):
                File "<pyshell#1 0>", line 1, in <module>
                cont.open("http ://www.google.com" )
                File "C:\Python25\li b\webbrowser.py ", line 185, in open
                p = subprocess.Pope n(cmdline, close_fds=True, preexec_fn=sets id)
                File "C:\Python25\li b\subprocess.py ", line 551, in __init__
                raise ValueError("clo se_fds is not supported on Windows "
                ValueError: close_fds is not supported on Windows platforms
                >
                Looking in the docs on subprocess.Popo pen
                (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

                Comment

                • Dustan

                  #9
                  Re: webbrowser module's Firefox support

                  >
                  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!

                  Comment

                  Working...