本文整理汇总了Python中requests.auth.HTTPDigestAuth方法的典型用法代码示例。如果您正苦于以下问题:Python auth.HTTPDigestAuth方法的具体用法?Python auth.HTTPDigestAuth怎么用?Python auth.HTTPDigestAuth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.auth
的用法示例。
在下文中一共展示了auth.HTTPDigestAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setAuthMethod
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def setAuthMethod(self, auth_method):
"Set the authentication method to use for the requests."
self.auth_method = auth_method
if len(self.auth_credentials) == 2:
username, password = self.auth_credentials
if self.auth_method == "basic":
from requests.auth import HTTPBasicAuth
self.h.auth = HTTPBasicAuth(username, password)
elif self.auth_method == "digest":
from requests.auth import HTTPDigestAuth
self.h.auth = HTTPDigestAuth(username, password)
elif self.auth_method == "ntlm":
from requests_ntlm import HttpNtlmAuth
self.h.auth = HttpNtlmAuth(username, password)
elif self.auth_method == "kerberos":
from requests_kerberos import HTTPKerberosAuth
self.h.auth = HTTPKerberosAuth()
示例2: pair_confirm
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def pair_confirm(self, data, err_count=0):
while err_count < 10:
if err_count > 0:
print("Resending pair confirm request")
try:
# print(data)
r = session.post("https://" + str(self.config["TV"]["host"]) +":1926/"+str(self.config["TV"]["apiv"])+"/pair/grant", json=data, verify=False, auth=HTTPDigestAuth(self.config["TV"]["user"], self.config["TV"]["pass"]),timeout=2)
print (r.request.headers)
print (r.request.body)
print("Username for subsequent calls is: " + str(self.config["TV"]["user"]))
print("Password for subsequent calls is: " + str(self.config["TV"]["pass"]))
return print("The credentials are saved in the settings.ini file.")
except Exception:
# try again
err_count += 1
continue
else:
return print("The API is unreachable. Try restarting your TV and pairing again")
# sends a general GET request
示例3: get
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def get(self, path, verbose=True, err_count=0):
while err_count < int(self.config["DEFAULT"]["num_retries"]):
if verbose:
print("Sending GET request to", str(self.config["TV"]["protocol"]) + str(self.config["TV"]["host"]) + ":" + str(self.config["TV"]["port"]) + "/" + str(self.config["TV"]["apiv"]) + "/" + str(path))
try:
r = session.get(str(self.config["TV"]["protocol"]) + str(self.config["TV"]["host"]) + ":" + str(self.config["TV"]["port"]) + "/" + str(self.config["TV"]["apiv"]) + "/" + str(path), verify=False, auth=HTTPDigestAuth(str(self.config["TV"]["user"]), str(self.config["TV"]["pass"])), timeout=2)
except Exception:
err_count += 1
continue
if verbose:
print("Request sent!")
if len(r.text) > 0:
print(r.text)
return r.text
else:
if self.config["DEFAULT"]["mqtt_listen"].lower()=="true":
self.mqtt_update_status({"powerstate":"Off", "volume":None, "muted":False, "cur_app":None, "ambilight":None, "ambihue":False})
return json.dumps({"error":"Can not reach the API"})
# sends a general POST request
示例4: auth_method
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def auth_method(self, value):
"""Set the authentication method to use for the requests."""
self._auth_method = value
if len(self._auth_credentials) == 2:
username, password = self._auth_credentials
if self._auth_method == "basic":
from requests.auth import HTTPBasicAuth
self._session.auth = HTTPBasicAuth(username, password)
elif self._auth_method == "digest":
from requests.auth import HTTPDigestAuth
self._session.auth = HTTPDigestAuth(username, password)
elif self._auth_method == "ntlm":
from requests_ntlm import HttpNtlmAuth
self._session.auth = HttpNtlmAuth(username, password)
elif self._auth_method == "kerberos":
# On openSUSE, "zypper in krb5-devel" before installing the pip package
from requests_kerberos import HTTPKerberosAuth
self._session.auth = HTTPKerberosAuth()
示例5: target_function
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def target_function(self, url, creds):
name = threading.current_thread().name
user, password = creds
user = user.encode('utf-8').strip()
password = password.encode('utf-8').strip()
response = http_request(method="GET", url=url, auth=HTTPDigestAuth(user, password))
if response is not None and response.status_code != 401:
print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'".format(self.target,
self.port,
name, user,
password),
verbose=self.verbosity)
self.credentials.append((self.target, self.port, user, password))
if self.stop_on_success:
raise Threads.StopThreadPoolExecutor
else:
print_error(
"Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'".format(self.target, self.port,
name, user, password),
verbose=self.verbosity)
示例6: target_function
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def target_function(self, url, user, password):
name = threading.current_thread().name
user = user.encode('utf-8').strip()
password = password.encode('utf-8').strip()
response = http_request(method="GET", url=url, auth=HTTPDigestAuth(user, password))
if response is not None and response.status_code != 401:
print_success("Target: {}:{} {}: Authentication Succeed - Username: '{}' Password: '{}'"
.format(self.target, self.port, name, user, password), verbose=self.verbosity)
self.credentials.append((self.target, self.port, user, password))
if self.stop_on_success:
raise Threads.StopThreadPoolExecutor
else:
print_error("Target: {}:{} {}: Authentication Failed - Username: '{}' Password: '{}'"
.format(self.target, self.port, name, user, password), verbose=self.verbosity)
示例7: _get_req_params
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def _get_req_params(self, params):
req_params = {
'headers': {
'Accept': 'application/json'
},
'timeout': self.conf.http_timeout,
}
auth_way = params.get('auth')
if auth_way in ['basic', 'digest']:
user = params.get('user')
password = params.get('password')
if auth_way == 'basic':
auth_class = auth.HTTPBasicAuth
else:
auth_class = auth.HTTPDigestAuth
req_params['auth'] = auth_class(user, password)
return req_params
示例8: __init__
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def __init__(self, h_url,server,port,username, password):
"""
Initializes the class. Set the h_url, server, username, and password variables.
:param h_url: str value. Must be equal to "http://" or "https://
:param server: str value. Must be valid IPv4 address or FQDN
:param port: str value. Equal to listening port of IMC server. example "8080" for http or "8443" for HTTPS
:param username: str value. Equal to username of IMC operator with privileges to access RESTUL API
:param password: str value. Equal to valid password of username defined above
:return:
returns HTTPDigestauth object
"""
super(HTTPDigestAuth,self).__init__()
self.h_url = h_url
self.server = server
self.port = port
self.username = username
self.password = password
self.url = self.h_url + self.server + ":" + self.port
self.creds = requests.auth.HTTPDigestAuth(self.username, self.password)
示例9: get_auth
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def get_auth(self):
"""
This method requests an authentication object from the HPE IMC NMS and returns an HTTPDigest Auth Object
:return:
"""
url = self.h_url + self.server + ":" + self.port
auth = requests.auth.HTTPDigestAuth(self.username,self.password)
auth_url = "/imcrs"
f_url = url + auth_url
try:
r = requests.get(f_url, auth=auth, headers=headers, verify=False)
return r.status_code
# checks for reqeusts exceptions
except requests.exceptions.RequestException as e:
return ("Error:\n" + str(e) + '\n\nThe IMC server address is invalid. Please try again')
set_imc_creds()
if r.status_code != 200: # checks for valid IMC credentials
return ("Error:\n" + str(e) +"Error: \n You're credentials are invalid. Please try again\n\n")
set_imc_creds()
示例10: walletJSONCall
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def walletJSONCall(self, method, params):
d = {
"id": "0",
"method": method,
"jsonrpc": "2.0",
"params": params
}
url = config.CONFIG.CAP.walletUri
log.L.debug("Calling wallet RPC " + url)
try:
r = requests.post(url, data=json.dumps(d), auth=HTTPDigestAuth(config.CONFIG.CAP.walletUsername, config.CONFIG.CAP.walletPassword), headers={"Content-Type": "application/json"})
if (r.status_code == 200):
j = json.loads(r.text)
if ('result' in j):
return(r.text)
else:
log.L.error("Wallet RPC error %s! Will not receive payments!" % (r.text))
return(None)
else:
log.L.error("Wallet RPC error %s! Will not receive payments!" % (r.status_code))
return(None)
except IOError:
return(None)
示例11: _get_http_auth
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def _get_http_auth(username: str, password: str, auth_type: str) -> AuthBase:
if auth_type == 'basic':
return HTTPBasicAuth(username, password)
if auth_type == 'digest':
return HTTPDigestAuth(username, password)
raise RetsClientError('unknown auth type %s' % auth_type)
示例12: get_requests_auth
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def get_requests_auth(auth: Optional[RawAuth], auth_type: Optional[str]) -> Optional[Union[HTTPDigestAuth, RawAuth]]:
if auth and auth_type == "digest":
return HTTPDigestAuth(*auth)
return auth
示例13: get_session
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def get_session(auth: Optional[Union[HTTPDigestAuth, RawAuth]] = None) -> Generator[requests.Session, None, None]:
with requests.Session() as session:
if auth is not None:
session.auth = auth
yield session
示例14: test_get_requests_auth
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def test_get_requests_auth():
assert isinstance(get_requests_auth(("test", "test"), "digest"), HTTPDigestAuth)
示例15: bruteForce
# 需要导入模块: from requests import auth [as 别名]
# 或者: from requests.auth import HTTPDigestAuth [as 别名]
def bruteForce(password, username):
#print str(username) + str(password)
tryComb = requests.post("http://" + target +":9990/management", auth=HTTPDigestAuth(str(username), str(password)),proxies=proxies,timeout=timeout)
statusCode = tryComb.status_code
if statusCode == 415:
print "\033[92m\033[1m[+]\033[0m Credential Found => " + username + ":" + password