def _send_request_safe_mode(self, method, url, **kwargs): """ Send an HTTP request, and catch any exception that might occur due to connection problems. This is equivalent of python-requests' safe_mode, which due to a bug, does currently *not* work together with Sessions. Once the issue is fixed in python-requests, this method should be removed. See: https://github.com/kennethreitz/requests/issues/888 """ try: return super(HttpSession, self).request(method, url, **kwargs) except (RequestException, ConnectionError, HTTPError, socket.timeout, socket.gaierror) as e: r = Response() r.error = e r.raw = HTTPResponse() # otherwise, tests fail r.status_code = 0 # with this status_code, content returns None return r
def _send_request_safe_mode(self, method, url, **kwargs): """ Send an HTTP request, and catch any exception that might occur due to connection problems. This is equivalent of python-requests' safe_mode, which due to a bug, does currently *not* work together with Sessions. Once the issue is fixed in python-requests, this method should be removed. See: https://github.com/kennethreitz/requests/issues/888 """ try: return super(HttpSession, self).request(method, url, **kwargs) except (MissingSchema, InvalidSchema, InvalidURL): raise except (RequestException, ConnectionError, HTTPError, socket.timeout, socket.gaierror) as e: r = Response() r.error = e r.raw = HTTPResponse() # otherwise, tests fail r.status_code = 0 # with this status_code, content returns None return r