def __init__(self, response): """Representation of a Pingdom API HTTP response.""" self.headers = response.headers self.content = response.json() if response.status_code >= 300: raise PingdomError(response)
def fetch(self): """Execute the request.""" try: msg = "`url`={0!r}\n`data`={1!r}".format(self.url, self.post_data) log.debug(msg) response = getattr(requests, self.method)(url=self.url, data=self.post_data, auth=self.auth, headers=self.headers) except requests.exceptions.RequestException, e: raise PingdomError(e)
def __init__(self, response): """Representation of a Pingdom API HTTP response.""" if response.headers.get('content-encoding') == 'gzip': self.data = gzip.GzipFile( fileobj=StringIO.StringIO(response.read())).read() else: self.data = response.read() self.headers = response.headers self.content = simplejson.loads(self.data) if 'error' in self.content: raise PingdomError(self.content)
def fetch(self): """Execute the request.""" try: response = urllib2.urlopen(self) except urllib2.HTTPError, e: raise PingdomError(e)