Search code examples
pythonhttpurlopen

Getting the error text from `urllib2.urlopen`


I used Python's urllib2.urlopen and got a 500 error from the server. How do I find the text of the error? I'm hoping that it has useful information.


Solution

  • from urllib2 import urlopen, HTTPError
    
    try:
        f = urlopen(url)
    except HTTPError, e:
        print(e.read())