I’m using the Harvest API (http://www.getharvest.com/api). When a client goes over it’s quota, a 503 response is returned. In that response there should be a header called “Retry-After” that tells me how long to wait before trying again.
How do I access the response headers when the call fails? I’m grabbing the HTTPError exception, but can’t figure out how to get the headers out of it.
I can get the response body with exception.read(), but that’s just the body without headers.
Some relevant code:
try:
request = urllib2.Request( url=self.uri+url, headers=self.headers )
r = urllib2.urlopen(request)
xml = r.read()
return parseString( xml )
except urllib2.HTTPError as err:
logger.debug("EXCEPTION: %s" % err.read() )
Try this:
It’s a dictionary, thus use
err.headers['Retry-After']