def _request(self, method, uri, body=None, params=None, extra_headers=None): p = parse_url(uri) if not p.host: uri = self.get_url(uri) try: r = self.conn.request(method, uri, data=body, params=params, headers=extra_headers, timeout=self.timeout) except (requests.exceptions.SSLError, requests.exceptions.ConnectionError) as e: if self._ssladapter: # If we've already applied an adapter, this is another problem # Raise the corresponding sleepwaker exception. raise ConnectionError("Could not connect to uri %s: %s", uri, e) # Otherwise, mount adapter and retry the request self.conn.mount('https://', SSLAdapter(ssl.PROTOCOL_TLSv1)) self._ssladapter = True r = self.conn.request(method, uri, data=body, params=params, headers=extra_headers, timeout=self.timeout) self.response = r # check if good status response otherwise raise exception if not r.ok: HTTPError.raise_by_status(r) return r
def fake_request(*args, **kwargs): HTTPError.raise_by_status(response)