def __init__( self, host='localhost', port=DEFAULT_PORT, user=None, password=None, timeout=None): if isinstance(timeout, (int, long, float)): self._query_timeout = float(timeout) else: self._query_timeout = DEFAULT_TIMEOUT self.url = 'http://%s:%s' % (host, port) LOGGER.debug('Result url: %s' % self.url) self.user = user self.password = password self.host = host self.port = port if user and password: self.authenticate(self.url) else: LOGGER.warning( 'Either user or password missing, not using authentication.')
def authenticate(self, url): LOGGER.info( 'Setting auth in host "%s" with user: %s and password: %s.' % (self.host, self.user, self.password)) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(realm=None, uri=url, user=self.user, passwd=self.password) opener = urllib2.build_opener( urllib2.HTTPBasicAuthHandler(password_manager), urllib2.HTTPDigestAuthHandler(password_manager)) urllib2.install_opener(opener) urllib2.urlopen(url)
def authenticate(self, url): LOGGER.info( 'Setting auth in host "%s" with user: %s and password: %s.' % (self.host, self.user, self.password)) password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password( realm=None, uri=url, user=self.user, passwd=self.password) opener = urllib2.build_opener( urllib2.HTTPBasicAuthHandler(password_manager), urllib2.HTTPDigestAuthHandler(password_manager) ) urllib2.install_opener(opener) urllib2.urlopen(url)
def __init__(self, host='localhost', port=DEFAULT_PORT, user=None, password=None, timeout=None): if isinstance(timeout, (int, long, float)): self._query_timeout = float(timeout) else: self._query_timeout = DEFAULT_TIMEOUT self.url = 'http://%s:%s' % (host, port) LOGGER.debug('Result url: %s' % self.url) self.user = user self.password = password self.host = host self.port = port if user and password: self.authenticate(self.url) else: LOGGER.warning( 'Either user or password missing, not using authentication.')