473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

webbrowser module bug?


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

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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthias Huening | last post by:
Hi, os.startfile('http://www.python.org') works fine on WinXP with IE as default webbrowser. With Mozilla Firefox 0.9 as default webbrowser, however, I get an error. Firefox starts, the page...
5
by: SPE - Stani's Python Editor | last post by:
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: >>> import webbrowser >>>...
19
by: Blair P. Houghton | last post by:
I'm just learning Python, so bear with. I was messing around with the webbrowser module and decided it was pretty cool to have the browser open a URL from within a python script, so I wrote a...
0
by: robin | last post by:
hi, i'm using the webbrowser module to open url's in safari or firefox. specifically i'm using the webbrowser.open('http://...', new=0) command. however, even though i say new=0 my url is...
8
by: Dustan | last post by:
At http://docs.python.org/whatsnew/modules.html on the webbrowser module, it says "A number of additional browsers were added to the supported list such as Firefox, Opera, Konqueror, and elinks." ...
4
by: Gregory Bloom | last post by:
I'm running Python 2.5 under Windows. If I fire up IDLE and enter: it works like a champ, opening the page in Firefox. Same thing goes from a Windows cmd shell: it works as advertised. But...
1
by: pmclinn | last post by:
I have some webbrowser code using the .net 2.0 control on a form. I want to remove the form and run the proceedure from a module but I cannot seem to get the code to work. Code in form that...
2
by: krishnakant Mane | last post by:
hello all, as I posted in my previous thread, I am generating html reports for my client software. I am yet to find a satisfactory module which can help me actually create headings, bold and...
2
by: scottbvfx | last post by:
Hi, I'm trying to launch a web browser along with an html file with a fragment identifier in its path. I'm using the webbrowser module for this. ie....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.