Connecting Tech Pros Worldwide Forums | Help | Site Map

webbrowser module bug?

Ron Adam
Guest
 
Posts: n/a
#1: May 24 '07

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.
Quote:
Quote:
Quote:
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
Quote:
Quote:
Quote:
>>>
It opens firefox as expected, but the url is ...

file:///home/ron/%22http://www.python.org%22

Which of course doesn't do what is expected.

Any ideas?

Ron




kyosohma@gmail.com
Guest
 
Posts: n/a
#2: May 25 '07

re: webbrowser module bug?


On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
Quote:
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.
Quote:
Quote:
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
Quote:
Quote:
>>>
>
It opens firefox as expected, but the url is ...
>
file:///home/ron/%22http://www.python.org%22
>
Which of course doesn't do what is expected.
>
Any ideas?
>
Ron
I don't know. This works for me with Python 2.4 on Windows XP SP2. The
docs don't say much (http://docs.python.org/lib/module-
webbrowser.html). Maybe it would be beneficial to read the module's
code? Or use the "register" command manually?

Mike

Ron Adam
Guest
 
Posts: n/a
#3: May 25 '07

re: webbrowser module bug?


kyosohma@gmail.com wrote:
Quote:
On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
Quote:
>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.
Quote:
> >>import webbrowser
> >>webbrowser.open('http://www.python.org')
>True
Quote:
> >>>
>>
>It opens firefox as expected, but the url is ...
>>
> file:///home/ron/%22http://www.python.org%22
>>
>Which of course doesn't do what is expected.
>>
>Any ideas?
>>
>Ron
>
I don't know. This works for me with Python 2.4 on Windows XP SP2. The
docs don't say much (http://docs.python.org/lib/module-
webbrowser.html). Maybe it would be beneficial to read the module's
code? Or use the "register" command manually?
It works for me on python 2.4 also, but not on later versions.

Looks like I'll need to try to test the url at the point where it calls the
browser from webbrowser.py.

Can someone else test this on python 2.5?

Ron


Steve Holden
Guest
 
Posts: n/a
#4: May 25 '07

re: webbrowser module bug?


Ron Adam wrote:
Quote:
kyosohma@gmail.com wrote:
Quote:
>On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
Quote:
>>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
>>>
>>Which of course doesn't do what is expected.
>>>
>>Any ideas?
>>>
>>Ron
>I don't know. This works for me with Python 2.4 on Windows XP SP2. The
>docs don't say much (http://docs.python.org/lib/module-
>webbrowser.html). Maybe it would be beneficial to read the module's
>code? Or use the "register" command manually?
>
It works for me on python 2.4 also, but not on later versions.
>
Looks like I'll need to try to test the url at the point where it calls the
browser from webbrowser.py.
>
Can someone else test this on python 2.5?
>
On my Windows laptop it works on 2.4.1 and 2.5.1 native, but not on
2.5.1 for Cygwin.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

Steve Holden
Guest
 
Posts: n/a
#5: May 25 '07

re: webbrowser module bug?


Ron Adam wrote:
Quote:
kyosohma@gmail.com wrote:
Quote:
>On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
Quote:
>>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
>>>
>>Which of course doesn't do what is expected.
>>>
>>Any ideas?
>>>
>>Ron
>I don't know. This works for me with Python 2.4 on Windows XP SP2. The
>docs don't say much (http://docs.python.org/lib/module-
>webbrowser.html). Maybe it would be beneficial to read the module's
>code? Or use the "register" command manually?
>
It works for me on python 2.4 also, but not on later versions.
>
Looks like I'll need to try to test the url at the point where it calls the
browser from webbrowser.py.
>
Can someone else test this on python 2.5?
>
On my Windows laptop it works on 2.4.1 and 2.5.1 native, but not on
2.5.1 for Cygwin.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
Brian van den Broek
Guest
 
Posts: n/a
#6: May 25 '07

re: webbrowser module bug?


Ron Adam said unto the world upon 05/25/2007 12:28 PM:
Quote:
kyosohma@gmail.com wrote:
Quote:
>On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
Quote:
>>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
>>>
>>Which of course doesn't do what is expected.
>>>
>>Any ideas?
<snip>
Quote:
>
It works for me on python 2.4 also, but not on later versions.
>
Looks like I'll need to try to test the url at the point where it calls the
browser from webbrowser.py.
>
Can someone else test this on python 2.5?
>
Ron
Works fine for me on ubuntu 7.04 (fiesty) with Python 2.5.1c1, which
appear to be your set-up, too.

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.
Quote:
Quote:
Quote:
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
Quote:
Quote:
Quote:
>>>

Best,

Brian vdB

Ron Adam
Guest
 
Posts: n/a
#7: May 25 '07

re: webbrowser module bug?


Brian van den Broek wrote:
Quote:
Ron Adam said unto the world upon 05/25/2007 12:28 PM:
Quote:
>kyosohma@gmail.com wrote:
Quote:
>>On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
>>>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
>>>>
>>>Which of course doesn't do what is expected.
>>>>
>>>Any ideas?
>
<snip>
>
Quote:
>It works for me on python 2.4 also, but not on later versions.
>>
>Looks like I'll need to try to test the url at the point where it calls the
>browser from webbrowser.py.
>>
>Can someone else test this on python 2.5?
>>
>Ron
>
Works fine for me on ubuntu 7.04 (fiesty) with Python 2.5.1c1, which
appear to be your set-up, too.
>
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.
Quote:
Quote:
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
Quote:
Quote:
>>>
>
Best,
>
Brian vdB
Thanks,

This is strange. Now I have no idea where to look. (?)


I get the same incorrect results doing...

ron@home:~$ python2.5 -m webbrowser 'http://www.python.org'

Firefox attempts to open...

file:///home/ron/%22http://www.python.org%22


The following works ok:

ron@home:~$ firefox 'http://www.python.org'


Works in the Ubuntu 2.4.4 dist (But blocks until the browser is closed.)

Doesn't work in the Ubuntu 2.5.1c1 dist
Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25)

Doesn't work in the 2.5 maintenance branch
Python 2.5 (release25-maint:54563, May 24 2007, 18:33:45)

Works in the 2.6 branch (trunk)
Works in the 3.0 branch


I'll try uninstalling and reinstalling. The Ubuntu 2.5 dist.

None of the svn versions are on the path, so it shouldn't be a path
conflict with them.

Ron


Ron Adam
Guest
 
Posts: n/a
#8: May 25 '07

re: webbrowser module bug?



Steve Holden wrote:
Quote:
Ron Adam wrote:
Quote:
>kyosohma@gmail.com wrote:
Quote:
>>On May 24, 5:03 pm, Ron Adam <r...@ronadam.comwrote:
>>>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
>>>>
>>>Which of course doesn't do what is expected.
>>>>
>>>Any ideas?
>>>>
>>>Ron
>>I don't know. This works for me with Python 2.4 on Windows XP SP2. The
>>docs don't say much (http://docs.python.org/lib/module-
>>webbrowser.html). Maybe it would be beneficial to read the module's
>>code? Or use the "register" command manually?
>It works for me on python 2.4 also, but not on later versions.
>>
>Looks like I'll need to try to test the url at the point where it calls the
>browser from webbrowser.py.
>>
>Can someone else test this on python 2.5?
>>
On my Windows laptop it works on 2.4.1 and 2.5.1 native, but not on
2.5.1 for Cygwin.
Does it mangle the url in the same way?

If so, then that would be enough to file a bug report.

It's maybe not due to the webbrowser module it self, but maybe something
else that's platform dependent?

Can anyone else reproduce this?

Ron


Paul Boddie
Guest
 
Posts: n/a
#9: May 25 '07

re: webbrowser module bug?


On 25 May, 00:03, Ron Adam <r...@ronadam.comwrote:
Quote:
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.
Quote:
Quote:
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
Quote:
Quote:
>>>
>
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

Ron Adam
Guest
 
Posts: n/a
#10: May 25 '07

re: webbrowser module bug?


Paul Boddie wrote:
Quote:
On 25 May, 00:03, Ron Adam <r...@ronadam.comwrote:
Quote:
>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.
Quote:
> >>import webbrowser
> >>webbrowser.open('http://www.python.org')
>True
Quote:
> >>>
>>
>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
Quote:
Quote:
Quote:
>>subprocess.Popen(['firefox', 'http://python.org'])
<subprocess.Popen object at 0xb7ddbeec>


This reproduces the problem I'm having.
Quote:
Quote:
Quote:
>>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.

Cheers,
Ron





Ron Adam
Guest
 
Posts: n/a
#11: May 25 '07

re: webbrowser module bug?


Ron Adam wrote:
Quote:
Paul Boddie wrote:
Quote:
>On 25 May, 00:03, Ron Adam <r...@ronadam.comwrote:
Quote:
>>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
>
Quote:
Quote:
>>subprocess.Popen(['firefox', 'http://python.org'])
<subprocess.Popen object at 0xb7ddbeec>
>
>
This reproduces the problem I'm having.
>
Quote:
Quote:
>>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

Ron Adam
Guest
 
Posts: n/a
#12: May 25 '07

re: webbrowser module bug?


Ron Adam wrote:
Quote:
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.
A bit more follow up... so others can find this and avoid a lot of
debugging, head scratching, computer smashing or worse.

Reseting the default browser with the gnome default application window
confirmed this. The browser selection can either have the quotes around
the args "%s" paremteter, or not depending on how and what sets it.

Seems to me it should be quoted unless spaces in path names are never a
problem in Linux. So this could be both a python bug and a Gnome desktop
bug. Firefox probably does the right thing by putting the quotes around
it, but that causes problems for webbrowser.py, which doesn't expect them.

Since the python trunk (2.6) has been changed to get the browser name in a
different way, it won't be a problem for python 2.6.

To check the args parameter or reset the default browser in the gnome
desktop, use the gnome default application panel.

$ gnome-default-applications-properties

You can then either remove the extra quotes from the "%s" or reset the browser.


Cheers,
Ron





Paul Boddie
Guest
 
Posts: n/a
#13: May 26 '07

re: webbrowser module bug?


Ron Adam wrote:
Quote:
>
Reseting the default browser with the gnome default application window
confirmed this. The browser selection can either have the quotes around
the args "%s" paremteter, or not depending on how and what sets it.
>
Seems to me it should be quoted unless spaces in path names are never a
problem in Linux. So this could be both a python bug and a Gnome desktop
bug. Firefox probably does the right thing by putting the quotes around
it, but that causes problems for webbrowser.py, which doesn't expect them.
Quoting arguments in the way described is the safe, easy option (with
some potential problems with ' characters that can be worked around),
and I imagine that it's done precisely because other applications
could pass a path with spaces as the URL, and that such applications
would be invoking the command in a shell environment. Sadly, this
conflicts with any other precautionary measures, causing a degree of
"overquoting".

Resetting the GNOME default is a workaround, but I'm not convinced
that it would be satisfactory. What happens if you try and open an
HTML file, in the file browser or some other application which uses
the desktop preferences, where the filename contains spaces?

Paul

Ron Adam
Guest
 
Posts: n/a
#14: May 26 '07

re: webbrowser module bug?


Paul Boddie wrote:
Quote:
Ron Adam wrote:
Quote:
>Reseting the default browser with the gnome default application window
>confirmed this. The browser selection can either have the quotes around
>the args "%s" paremteter, or not depending on how and what sets it.
>>
>Seems to me it should be quoted unless spaces in path names are never a
>problem in Linux. So this could be both a python bug and a Gnome desktop
>bug. Firefox probably does the right thing by putting the quotes around
>it, but that causes problems for webbrowser.py, which doesn't expect them.
>
Quoting arguments in the way described is the safe, easy option (with
some potential problems with ' characters that can be worked around),
and I imagine that it's done precisely because other applications
could pass a path with spaces as the URL, and that such applications
would be invoking the command in a shell environment. Sadly, this
conflicts with any other precautionary measures, causing a degree of
"overquoting".
>
Resetting the GNOME default is a workaround, but I'm not convinced
that it would be satisfactory. What happens if you try and open an
HTML file, in the file browser or some other application which uses
the desktop preferences, where the filename contains spaces?
I'm not sure how to test this. Most things I can think of call the web
browser directly. Maybe a link in an email?

Yes, it is a work around. The webbrowser module needs to be smarter about
quotes. As I said, this is fixed in 2.6 already. I emailed the module
maintainer, and will probably file a bug report too.

Ron






Ron Adam
Guest
 
Posts: n/a
#15: May 26 '07

re: webbrowser module bug?


Paul Boddie wrote:
Quote:
Ron Adam wrote:
Quote:
>Reseting the default browser with the gnome default application window
>confirmed this. The browser selection can either have the quotes around
>the args "%s" paremteter, or not depending on how and what sets it.
>>
>Seems to me it should be quoted unless spaces in path names are never a
>problem in Linux. So this could be both a python bug and a Gnome desktop
>bug. Firefox probably does the right thing by putting the quotes around
>it, but that causes problems for webbrowser.py, which doesn't expect them.
>
Quoting arguments in the way described is the safe, easy option (with
some potential problems with ' characters that can be worked around),
and I imagine that it's done precisely because other applications
could pass a path with spaces as the URL, and that such applications
would be invoking the command in a shell environment. Sadly, this
conflicts with any other precautionary measures, causing a degree of
"overquoting".
>
Resetting the GNOME default is a workaround, but I'm not convinced
that it would be satisfactory. What happens if you try and open an
HTML file, in the file browser or some other application which uses
the desktop preferences, where the filename contains spaces?
I'm not sure how to test this. Most things I can think of call the web
browser directly. Maybe a link in an email?

Yes, it is a work around. The webbrowser module needs to be smarter about
quotes. As I said, this is fixed in 2.6 already. I emailed the module
maintainer, and will probably file a bug report too.

Ron






Closed Thread