Question about using urllib2 to load a url

ken ken.carlino at gmail.com
Sun Apr 1 17:52:12 EDT 2007


Hi,

i have the following code to load a url.
My question is what if I try to load an invalide url ("http://
www.heise.de/"), will I get an IOException? or it will wait forever?

Thanks for any help.

 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)

    txheaders = {'User-agent': 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3'}

    try:
        req = Request(url, txdata, txheaders)
        handle = urlopen(req)
    except IOError, e:
        print e
        print 'Failed to open %s' % url
        return 0;




More information about the Python-list mailing list