示例#1
0
    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)
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
 def fetch(self):
     """Execute the request."""
     try:
         response = urllib2.urlopen(self)
     except urllib2.HTTPError, e:
         raise PingdomError(e)