#!/usr/bin/python import urllib2 try: s='404 error' asock = urllib2.urlopen("http://www.leilene.net/Leilene%20Dec%20000.JPG") except urllib2.HTTPError, e: if e.code = 404 then open('/home/levon/testing', 'a').write(s) open('/home/levon/testing', 'a').write(s)