473,242 Members | 1,817 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,242 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 2054
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.