freshbooks/refreshbooks — comment on commit 4bf61a1bf4b8ce18c6302a068c46bf46ffaccba5
File:  line 0
By benhoyt:

Nice. Actually, it's easy to get the error content with urllib2 -- just .read() the HTTPError instance:

import sys
import urllib2

def get_url(url):
try:
f = urllib2.urlopen(url)
content = f.read()
status = 200
except urllib2.HTTPError, e:
content = e.read()
status = e.code
return (content, status)

if __name__ == '__main__':
url = sys.argv[1]
content, status = get_url(url)
print 'Url:', url
print 'Status:', status
print
print content[:1024]