Python urllib2 URLError HTTP status code.

前端 未结 2 1968
再見小時候
再見小時候 2021-02-03 20:45

I want to grab the HTTP status code once it raises a URLError exception:

I tried this but didn\'t help:

except URLError, e:
    logger.warning( \'It see         


        
2条回答
  •  情歌与酒
    2021-02-03 21:25

    Not sure why you are getting this error. If you are using urllib2 this should help:

    import urllib2
    from urllib2 import URLError
    
    try:
        urllib2.urlopen(url)
    except URLError, e:
        print e.code
    

提交回复
热议问题