Firefox bug in webbrowser module on Ubuntu?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SPE - Stani's Python Editor

    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:
    [color=blue][color=green][color=darkred]
    >>> import webbrowser
    >>> webbrowser.open ("http://www.python.org" )[/color][/color][/color]

    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:
    [color=blue][color=green][color=darkred]
    >>> import webbrowser
    >>> webbrowser.brow ser[/color][/color][/color]
    'netscape'

    In the _browsers attribute there seems to be an entry for
    'mozilla-firefox', but doesn't seem to work[color=blue][color=green][color=darkred]
    >>> webbrowser._bro wsers[/color][/color][/color]
    {'galeon': [None, <webbrowser.Gal eon instance at 0xb7d261cc>],
    'mozilla': [None, <webbrowser.Net scape instance at 0xb7d2608c>],
    'mozilla-firefox': [None, <webbrowser.Net scape instance at
    0xb7d2612c>], 'w3m': [None, <webbrowser.Gen ericBrowser instance at
    0xb7d22fec>]}

    The tryorder is...[color=blue][color=green][color=darkred]
    >>> webbrowser._try order[/color][/color][/color]
    ['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
    --
    Free python IDE for Windows,Mac & Linux with UML,PyChecker,Debugger,GUI design,Blender & more


  • Paul Boddie

    #2
    Re: Firefox bug in webbrowser module on Ubuntu?!

    SPE - Stani's Python Editor wrote:[color=blue]
    >
    > During optimizing SPE for Ubuntu, I found something strange. I have
    > Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not
    > working:
    >[color=green][color=darkred]
    > >>> import webbrowser
    > >>> webbrowser.open ("http://www.python.org" )[/color][/color]
    >
    > It does not throw an exception, but is not able to launch a browser.[/color]

    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:



    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

    Comment

    • ncf

      #3
      Re: Firefox bug in webbrowser module on Ubuntu?!

      This section is the cause of the problem:

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

      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._isc ommand("firefox "):
      webbrowser.regi ster("firefox", None, Netscape("firef ox"))
      webbrowser.open ("http://www.google.com/")

      ((Untested))

      Best of luck


      SPE - Stani's Python Editor wrote:[color=blue]
      > 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:
      >[color=green][color=darkred]
      > >>> import webbrowser
      > >>> webbrowser.open ("http://www.python.org" )[/color][/color]
      >
      > 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:
      >[color=green][color=darkred]
      > >>> import webbrowser
      > >>> webbrowser.brow ser[/color][/color]
      > 'netscape'
      >
      > In the _browsers attribute there seems to be an entry for
      > 'mozilla-firefox', but doesn't seem to work[color=green][color=darkred]
      > >>> webbrowser._bro wsers[/color][/color]
      > {'galeon': [None, <webbrowser.Gal eon instance at 0xb7d261cc>],
      > 'mozilla': [None, <webbrowser.Net scape instance at 0xb7d2608c>],
      > 'mozilla-firefox': [None, <webbrowser.Net scape instance at
      > 0xb7d2612c>], 'w3m': [None, <webbrowser.Gen ericBrowser instance at
      > 0xb7d22fec>]}
      >
      > The tryorder is...[color=green][color=darkred]
      > >>> webbrowser._try order[/color][/color]
      > ['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[/color]

      Comment

      • skip@pobox.com

        #4
        Re: Firefox bug in webbrowser module on Ubuntu?!


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

        In SVN trunk (aka 2.5a0) this code is

        for browser in ("mozilla-firefox", "firefox",
        "mozilla-firebird", "firebird",
        "mozilla", "netscape") :
        if _iscommand(brow ser):
        register(browse r, 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

        Comment

        • SPE - Stani's Python Editor

          #5
          Re: Firefox bug in webbrowser module on Ubuntu?!

          This seems ok...[color=blue][color=green][color=darkred]
          >>> import webbrowser
          >>> webbrowser._isc ommand("firefox ")[/color][/color][/color]
          True[color=blue][color=green][color=darkred]
          >>> webbrowser.regi ster("firefox", None,webbrowser .Netscape("fire fox"))
          >>> webbrowser._bro wsers[/color][/color][/color]
          {'galeon': [None, <webbrowser.Gal eon instance at 0xb7d471cc>],
          'firefox': [None, <webbrowser.Net scape instance at 0xb7d43bcc>],
          'mozilla': [None, <webbrowser.Net scape instance at 0xb7d4708c>],
          'mozilla-firefox': [None, <webbrowser.Net scape instance at
          0xb7d4712c>], 'w3m': [None, <webbrowser.Gen ericBrowser instance at
          0xb7d43fec>]}

          But it is still not working...[color=blue][color=green][color=darkred]
          >>> webbrowser.open ("http://www.python.org" )[/color][/color][/color]
          ....doesn't do anything

          However...[color=blue][color=green][color=darkred]
          >>> import os
          >>> os.path.exists( '/usr/bin/firefox')[/color][/color][/color]
          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.

          Comment

          • Jarek Zgoda

            #6
            Re: Firefox bug in webbrowser module on Ubuntu?!

            Paul Boddie napisa³(a):
            [color=blue]
            > 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.[/color]

            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

            Comment

            Working...