def get_file_http(self, url, path, revision): logging.info('Fetching file from %s' % url) try: request = URLRequest(url) if self.username: auth_string = base64.b64encode('%s:%s' % (self.username, self.password)) request.add_header('Authorization', 'Basic %s' % auth_string) return urlopen(request).read() except HTTPError as e: if e.code == 404: logging.error('404') raise FileNotFoundError(path, revision) else: msg = "HTTP error code %d when fetching file from %s: %s" % \ (e.code, url, e) logging.error(msg) raise SCMError(msg) except Exception as e: msg = "Unexpected error fetching file from %s: %s" % (url, e) logging.error(msg) raise SCMError(msg)
def _build_request(self, url, body=None, headers={}, username=None, password=None): r = URLRequest(url, body, headers) if username is not None and password is not None: auth_key = username + ':' + password r.add_header(HTTPBasicAuthHandler.auth_header, 'Basic %s' % base64.b64encode(auth_key.encode('utf-8'))) return r
def _build_request(self, url, body=None, headers={}, username=None, password=None): r = URLRequest(url, body, headers) if username is not None and password is not None: auth_key = username + ':' + password r.add_header( HTTPBasicAuthHandler.auth_header, 'Basic %s' % base64.b64encode(auth_key.encode('utf-8'))) return r