Example #1
0
 def _verify_get(self,
                 url,
                 times=0,
                 headers=default_headers,
                 refresh_ip=False,
                 timeout=download_timeout):
     headers.update({'User-Agent': self._user_agent})
     try:
         response = self._http_client.get(url,
                                          headers=headers,
                                          timeout=timeout)
         if response.status_code == 200:
             logging.debug(response.headers)
             pass
         elif response.status_code == 302:
             location = response.headers['Location']
             logging.debug("location: %s" % location)
             raise Error302()
         elif response.status_code == 403:
             raise Error403()
         elif response.status_code == 404:
             raise Error404()
         elif response.status_code == 502:
             raise Error502()
         else:
             raise ErrorStatusCode(response.status_code)
         return response
     except Error403, err:
         raise err
    def _verify_post(self, url, data=None, json=None, times=0, headers=default_headers, timeout=download_timeout):

        # headers.update({
        #     'User-Agent': self._user_agent,
        #     # "Proxy-Authorization": self.get_authHeader()
        # })

        try:
            response = self._http_client.post(url=url, data=data, json=json, headers=headers, timeout=timeout)
            if response.status_code == 200:
                logging.debug(response.headers)
                pass
            elif response.status_code == 302:
                location = response.headers['Location']
                logging.debug("location: %s" % location)
                raise Error302()
            elif response.status_code == 403:
                raise Error403()
            elif response.status_code == 404:
                raise Error404()
            elif response.status_code == 502:
                raise Error502()
            elif response.status_code == 503:
                raise Error503()
            else:
                raise ErrorStatusCode(response.status_code)
            return response
        except Error403, err:
            raise err
    def _verify_post(self, url, data=None, json=None, times=0):
        try:
            response = self._http_client.post(url, data, json)
            if response.status_code == 200:
                pass
            elif response.status_code == 302:
                location = response.headers['Location']
                logging.debug("location: %s" % location)
                raise Error302()
            elif response.status_code == 403:
                raise Error403()
            elif response.status_code == 404:
                raise Error404()
            elif response.status_code == 502:
                raise Error502()
            elif response.status_code == 503:
                raise Error503()
            else:
                raise ErrorStatusCode(response.status_code)
            return response

        except HttpClientError, err:
            times += 1
            if times < 3:
                return self._verify_post(url, data=data, json=json, times=times)
            else:
                raise err
Example #4
0
 def _check_response(self, response):
     if response.status_code == 200:
         logging.debug(response.headers)
         pass
     elif response.status_code == 302:
         location = response.headers['Location']
         logging.debug("location: %s" % location)
         raise Error302()
     elif response.status_code == 403:
         raise Error403()
     elif response.status_code == 404:
         raise Error404()
     elif response.status_code == 502:
         raise Error502()
     elif response.status_code == 503:
         raise Error503()
     else:
         raise ErrorStatusCode(response.status_code)
     return response