webbrowser module bug?

Ron Adam rrr at ronadam.com
Fri May 25 16:00:38 EDT 2007


Ron Adam wrote:
> Paul Boddie wrote:
>> On 25 May, 00:03, Ron Adam <r... at ronadam.com> wrote:
>>> Is anyone else having problems with the webbrowser module?
>>>
>>> Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25)
>>> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>  >>> import webbrowser
>>>  >>> webbrowser.open('http://www.python.org')
>>> True
>>>  >>>
>>>
>>> It opens firefox as expected, but the url is ...
>>>
>>>       file:///home/ron/%22http://www.python.org%22
>> Since %22 is the URL-encoded double-quote character ("), I can only
>> imagine that something is quoting the URL for the shell, resulting in
>> the following command:
>>
>> firefox '"http://www.python.org/"'
>>
>> Or something similar, at least. Firefox 1.5 seems to refuse to open
>> such URLs, though.
>>
>> Paul
> 
> Yes,  thats it.  I've traced it down the the subproccess.Popen call.
> 
> 
> This works
> 
>  >>> subprocess.Popen(['firefox', 'http://python.org'])
> <subprocess.Popen object at 0xb7ddbeec>
> 
> 
> This reproduces the problem I'm having.
> 
>  >>> subprocess.Popen(['firefox', '"http://python.org"'])
> <subprocess.Popen object at 0xb7ddbf4c>
> 
> The quoting does happen in the webbrowser module.
> 
> The cmdline is passed as...
> 
>      ['/usr/lib/firefox/firefox', '"http://python.org"']
> 
> 
> 
> I've traced it back to the following line where self.args is ['"%s"']
> 
> Line 187 in webbrowser.py:
> 
>          cmdline = [self.name] + [arg.replace("%s", url)
>                                   for arg in self.args]
> 
> Now I just need to figure out why self.args is double quoted.

Got it.

    It looks like the problem started when I told firefox to make itself 
the default browser.  That changed the way webbrowser.py figured out the 
browser to use.  So instead of trying them in order, it asked the gnome 
configure tool for it.

def register_X_browsers():
     # The default Gnome browser
     if _iscommand("gconftool-2"):
         # get the web browser string from gconftool
         gc = 'gconftool-2 -g /desktop/gnome/url-handlers/http/command 
2>/dev/null'
         out = os.popen(gc)
         commd = out.read().strip()
         retncode = out.close()


After this commd is:

     '/usr/lib/firefox/firefox "%s"'

It's then split, but the quotes aren't removed.  I'm not sure why this 
doesn't show up in 2.6.  Maybe it's been fixed there already.


Cheers,
    Ron




More information about the Python-list mailing list