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.op en('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
14 2101
Ron Adam wrote:
Paul Boddie wrote:
>On 25 May, 00:03, Ron Adam <r...@ronadam.c omwrote:
>>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.op en('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.Pop en call.
This works
>>subprocess.Po pen(['firefox', 'http://python.org'])
<subprocess.Pop en object at 0xb7ddbeec>
This reproduces the problem I'm having.
>>subprocess.Po pen(['firefox', '"http://python.org"'])
<subprocess.Pop en 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_brow sers():
# The default Gnome browser
if _iscommand("gco nftool-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().stri p()
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 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_brow sers():
# The default Gnome browser
if _iscommand("gco nftool-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().stri p()
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
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
"overquotin g".
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
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
"overquotin g".
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
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
"overquotin g".
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 gets loaded and then
Python gives me an error message (Traceback below). The same is true
for the webbowser module. Is this a Python problem or a Firefox
problem?
Matthias
|
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
>>> webbrowser.open("http://www.python.org")
It does not throw an exception, but is not able to launch a browser.
|
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 short script to open a local file the same way, using the
script file as an example target:
# browser-test.py
import webbrowser
import sys
|
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 always opened in a new
browser window.
what can i do, so my link is opened in an already open browser window?
|
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."
I just installed python 2.5, looking forward to being able to control
firefox without having to make it my default browser, but...
I don't seem to have that functionality. In IDLE:
{'windows-default': }
| |
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 if I open a cygwin bash shell and try the same thing from a python
prompt, I get:
Traceback (most recent call last):
|
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 works:
WebBrowser1.Navigate("http://website")
in the completed event handler I have this
Static quit As Integer = 0
If quit = 0 Then
|
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 italics etc without merging html with data
variables.
any ways I am right now doing the hamd coding myself. may be I have
overlooked some module.
right now I am in the process of trying templayer.
but my main issue is that when I use the
|
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. webbrowser.open('file:///C:/myfile.html#SomeEntryInTheHTML')
for some reason it is truncating the path to 'file:///C:/myfile.html'.
Does anyone know a way of getting the fragment identifier in there
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |