def head(self, url, params=None, check=True, **kwargs): """ Custom head request :param str url: request url :param dict params: request parameters :param bool check: check response :param kwargs: other params :return: requests's response object """ try: resp = requests.head(url, params=params, cookies=self.cookie, headers=self.header, proxies=self.proxy, timeout=self.timeout, verify=self.verify, **kwargs) except Exception as e: logger.log('ERROR', e.args) return None if not check: return resp if utils.check_response('HEAD', resp): return resp return None
def post(self, url, data=None, check=True, **kwargs): """ Custom post request :param str url: request url :param dict data: request data :param bool check: check response :param kwargs: other params :return: requests's response object """ try: resp = requests.post(url, data=data, cookies=self.cookie, headers=self.header, proxies=self.proxy, timeout=self.timeout, verify=self.verify, **kwargs) except Exception as e: logger.log('ERROR', e.args) return None if not check: return resp if utils.check_response('POST', resp): return resp return None
def delete(self, url, check=True, **kwargs): """ Custom delete request :param str url: request url :param bool check: check response :param kwargs: other params :return: response object """ session = requests.Session() session.trust_env = False try: resp = session.delete(url, cookies=self.cookie, headers=self.header, proxies=self.proxy, timeout=self.timeout, verify=self.verify, **kwargs) except Exception as e: logger.log('ERROR', e.args[0]) return None if not check: return resp if utils.check_response('DELETE', resp): return resp return None
def get(self, url, params=None, check=True, ignore=False, **kwargs): """ Custom get request :param str url: request url :param dict params: request parameters :param bool check: check response :param bool ignore: ignore error :param kwargs: other params :return: response object """ level = 'ERROR' if ignore: level = 'DEBUG' try: resp = requests.get(url, params=params, cookies=self.cookie, headers=self.header, proxies=self.proxy, timeout=self.timeout, verify=self.verify, **kwargs) except Exception as e: logger.log(level, e.args) return None if not check: return resp if utils.check_response('GET', resp): return resp return None
def get(self, url, params=None, check=True, ignore=False, raise_error=False, **kwargs): """ Custom get request :param str url: request url :param dict params: request parameters :param bool check: check response :param bool ignore: ignore error :param bool raise_error: raise error or not :param kwargs: other params :return: response object """ session = requests.Session() session.trust_env = False level = 'ERROR' if ignore: level = 'DEBUG' try: resp = session.get(url, params=params, cookies=self.cookie, headers=self.header, proxies=self.proxy, timeout=self.timeout, verify=self.verify, **kwargs) except Exception as e: if raise_error: if isinstance(e, requests.exceptions.ConnectTimeout): logger.log(level, e.args) raise e logger.log(level, e.args) return None if not check: return resp if utils.check_response('GET', resp): return resp return None