def authfetch(username,password,path="/",realm=realm): server.accept(2) import socket socket.setdefaulttimeout(5) uri = ("http://%s:%s" % server.server_address) + path auth = HTTPDigestAuthHandler() auth.add_password(realm,uri,username,password) opener = build_opener(auth) result = opener.open(uri) return result.read()
def authfetch(username, password, path="/", realm=realm): server.accept(2) import socket socket.setdefaulttimeout(5) uri = ("http://%s:%s" % server.server_address) + path auth = HTTPDigestAuthHandler() auth.add_password(realm, uri, username, password) opener = build_opener(auth) result = opener.open(uri) return result.read()
def add_authentication(self, realm, url, username, password): """ Set authentication credentials for the opener returned by :meth:`opener`. EXAMPLES:: sage: from sage.dev.digest_transport import DigestTransport sage: dt = DigestTransport() sage: dt.add_authentication("realm", "url", "username", "password") sage: dt.opener <urllib2.OpenerDirector instance at 0x...> """ assert self._opener is None authhandler = HTTPDigestAuthHandler() authhandler.add_password(realm, url, username, password) self._opener = build_opener(authhandler)