webbrowser module bug?

R

Ron Adam

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

kyosohma

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

Ron Adam

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
 
S

Steve Holden

Ron said:
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 ----------------
 
S

Steve Holden

Ron said:
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 ----------------
 
B

Brian van den Broek

Ron Adam said unto the world upon 05/25/2007 12:28 PM:
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?

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.

Best,

Brian vdB
 
R

Ron Adam

Brian said:
Ron Adam said unto the world upon 05/25/2007 12:28 PM:
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?

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

Ron Adam

Steve said:
Ron said:
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
 
P

Paul Boddie

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

Ron Adam

Paul said:
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 object at 0xb7ddbeec>


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

Ron Adam

Ron said:
Paul said:
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
 
R

Ron Adam

Ron said:
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
 
P

Paul Boddie

Ron said:
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
 
R

Ron Adam

Paul said:
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
 
R

Ron Adam

Paul said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top