By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,171 Members | 809 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,171 IT Pros & Developers. It's quick & easy.

webbrowser module bug?

P: n/a

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

May 24 '07 #1
Share this Question
Share on Google+
14 Replies


P: n/a
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?

Mike

May 25 '07 #2

P: n/a
ky******@gmail.com wrote:
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?

Ron
May 25 '07 #3

P: n/a
Ron Adam wrote:
ky******@gmail.com wrote:
>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.

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

May 25 '07 #4

P: n/a
Ron Adam wrote:
ky******@gmail.com wrote:
>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.

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 ----------------
May 25 '07 #5

P: n/a
Ron Adam said unto the world upon 05/25/2007 12:28 PM:
ky******@gmail.com wrote:
>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>
>
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.
>>import webbrowser
webbrowser.open('http://www.python.org')
True
>>>

Best,

Brian vdB

May 25 '07 #6

P: n/a
Brian van den Broek wrote:
Ron Adam said unto the world upon 05/25/2007 12:28 PM:
>ky******@gmail.com wrote:
>>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>
>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.
>>import webbrowser
>>webbrowser.open('http://www.python.org')
True
>>>

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
May 25 '07 #7

P: n/a

Steve Holden wrote:
Ron Adam wrote:
>ky******@gmail.com wrote:
>>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
May 25 '07 #8

P: n/a
On 25 May, 00:03, 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
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

May 25 '07 #9

P: n/a
Paul Boddie wrote:
On 25 May, 00:03, 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

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.

Cheers,
Ron

May 25 '07 #10

P: n/a
Ron Adam wrote:
Paul Boddie wrote:
>On 25 May, 00:03, 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
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

May 25 '07 #11

P: n/a
Ron Adam wrote:
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

May 25 '07 #12

P: n/a
Ron Adam wrote:
>
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

May 25 '07 #13

P: n/a
Paul Boddie wrote:
Ron Adam wrote:
>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


May 26 '07 #14

P: n/a
Paul Boddie wrote:
Ron Adam wrote:
>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


May 26 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.