any

from urllib2 import Request, urlopen, URLError, HTTPError
req = Request(‘http://bbs.csdn.net/callmewhy‘)  

try:
    response = urlopen(req)
except HTTPError, e:
    print ‘The server couldn\‘t fulfill the request.‘
    print ‘Error code: ‘, e.code    #HttpError是URLError的子类,
except URLError, e:
    print ‘We failed to reach a server.‘
    print ‘Reason: ‘, e.reason
else:
    print ‘No exception was raised.‘ 
时间: 2024-10-13 22:47:10