예제 #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_get(self, url):
     # kwargs.setdefault("allow_redirects", False)
     response = self._http_client.get(url)
     if response.status_code == 200:
         pass
     elif response.status_code == 302:
         location = response.headers['Location']
         user_verify_url = urljoin("http://qiye.qianzhan.com/", location)
         is_success = self.do_verify(user_verify_url)
         if is_success:
             response = self._verify_get(url)
         else:
             is_success = self.login()
             if is_success:
                 response = self._http_client.get(url)
             else:
                 raise Error302()
     elif response.status_code == 403:
         raise Error403()
     elif response.status_code == 404:
         is_success = self.login()
         if is_success:
             response = self._http_client.get(url)
         else:
             raise Error404()
     else:
         raise ErrorStatusCode()
     return response
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
 def _verify_get(self, url, **kwargs):
     kwargs.setdefault("allow_redirects", False)
     response = self._http_client.get(url, **kwargs)
     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()
     else:
         raise ErrorStatusCode()
     return response
예제 #6
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