def _do_get(url, headers, **kwargs): # More time please if 'timeout' not in kwargs: kwargs['timeout'] = 60 if 'allow_redirects' not in kwargs: kwargs['allow_redirects'] = True response = HTTP.get_with_timeout(url, headers=headers, **kwargs) return response.status_code, response.headers, response.content
def __init__(self, _db, collection, new_css=None, *args, **kwargs): kwargs['content_modifier'] = self.replace_css if new_css: self.new_css = new_css else: self.new_css = HTTP.get_with_timeout("http://www.daisy.org/z3986/2005/dtbook.2005.basic.css").content super(FeedbooksOPDSImporter, self).__init__( _db, collection, **kwargs )
def get_catalogue(self, name): response = HTTP.get_with_timeout( self.CATALOGUES_ENDPOINT, headers=self.default_headers ) if response.status_code == 200: catalogues = response.json().get('results') catalogue = filter(lambda c: c.get('name') == name, catalogues) if catalogue: return catalogue[0] else: return None
def _get(self, url, headers=None): """Make a normal HTTP request, but include an authentication header with the credentials for the collection. """ username = self.username password = self.password headers = dict(headers or {}) auth_header = "Basic %s" % base64.b64encode("%s:%s" % (username, password)) headers['Authorization'] = auth_header return HTTP.get_with_timeout(url, headers=headers)
def _get(self, url, headers): return HTTP.get_with_timeout(url, headers=headers).json()