Catching webbrowser error in RedHat

Graeme Mathieson mathie at wossname.org.uk
Tue Apr 1 10:25:31 EST 2003


In <v8edjq9cc4o13 at corp.supernews.com>,
on Sun, 30 Mar 2003 10:24:56 -0800, "Lance" <lbrannma at cablespeed.com> writes:

>         try:
>             webbrowser.open(fname)
>         except:
>             print "ERROR: "+fname+" not found."

> 2. If the try block is not successful, the Redhat splash screen shows,
> followed by an ugly system message box saying that the file could not be
> found. I want only the message in my except clause to display, not the
> system message.

Check to see if the file exists before loading it up in the web browser?
It will not help for other errors, but that might be the most common
one, eh?  If it's a local file, something along the lines of:

try:
    import urllib
    # This will raise an IOError if the file cannot be found
    fname_check = urllib.URLopener().open(fname)
    webbrowser.open(fname)
except IOError, data:
    print "ERROR: " + fname + "not found: " + data

might do the trick?  Of course, if fname is a remote file, I think
that's going to retrieve it if it does exist, which is probably not a
good idea if it is a large file...    
-- 
Right now, there are scr1pt k1dd13s plotting to DDoS my network, my co-lo
server is not responding  to pings and  the people that I IRC with may be
involved in both.  I'm  sysadmin Graeme Mathieson and this is the longest
day of my life.                               http://www.wossname.org.uk/




More information about the Python-list mailing list