本文整理汇总了Python中requests_ntlm.HttpNtlmAuth方法的典型用法代码示例。如果您正苦于以下问题:Python requests_ntlm.HttpNtlmAuth方法的具体用法?Python requests_ntlm.HttpNtlmAuth怎么用?Python requests_ntlm.HttpNtlmAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests_ntlm
的用法示例。
在下文中一共展示了requests_ntlm.HttpNtlmAuth方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setAuthMethod
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [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: auth_method
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [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()
示例3: connection_parameters
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def connection_parameters(self) -> Dict[str, Any]:
"""Construct connection related parameters.
Returns:
A dictionary with connection-related parameters in the format
expected by ``requests``. The following keys can be present:
``proxies``, ``verify``, and ``auth``.
"""
request_kwargs = {
'verify': self.verify
}
if self.proxies:
if 'urls' in self.proxies:
request_kwargs['proxies'] = self.proxies['urls']
if 'username_ntlm' in self.proxies and 'password_ntlm' in self.proxies:
request_kwargs['auth'] = HttpNtlmAuth(
self.proxies['username_ntlm'],
self.proxies['password_ntlm']
)
return request_kwargs
示例4: test_config_ntlm_legacy
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def test_config_ntlm_legacy(self, caplog):
instance = {'ntlm_domain': 'domain\\user', 'password': 'pass'}
init_config = {}
# Trigger lazy import
http = RequestsWrapper(instance, init_config)
assert isinstance(http.options['auth'], requests_ntlm.HttpNtlmAuth)
with mock.patch('datadog_checks.base.utils.http.requests_ntlm.HttpNtlmAuth') as m:
RequestsWrapper(instance, init_config)
m.assert_called_once_with('domain\\user', 'pass')
assert (
'The ability to use NTLM auth without explicitly setting auth_type to '
'`ntlm` is deprecated and will be removed in Agent 8'
) in caplog.text
示例5: __init__
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def __init__(self, host, port, ssl_verify, username, password, logger):
self.url = f"https://{host}:{port}/st/console/api/v1.0"
self.ntlm_auth = HttpNtlmAuth(username, password)
self.password = password
self.logger = logger
self.ssl_verify = ssl_verify
示例6: setup_hook_httpntlmauth
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def setup_hook_httpntlmauth(request):
if "httpntlmauth" in request:
from requests_ntlm import HttpNtlmAuth
auth_account = request.pop("httpntlmauth")
request["auth"] = HttpNtlmAuth(
auth_account["username"], auth_account["password"]
)
示例7: get_auth_obj
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def get_auth_obj(method, user, password):
"""
Generates an authentication code object depending of method as parameter:
* "basic"
* "digest"
* "ntlm"
.. warning:
This function may be removed in future versions of GoLismero.
:param method: Auth method: basic, digest, ntlm.
:type method: str
:param user: string with user text
:type user: str
:param password: string with password text
:type password: str
:return: an object with authentication or None if error/problem.
"""
m_auth_obj = None
if method:
m_method = method.lower()
if m_method == "basic":
m_auth_obj = HTTPBasicAuth(user, password)
elif m_method == "digest":
m_auth_obj = HTTPDigestAuth(user, password)
elif m_method == "ntlm":
m_auth_obj = HttpNtlmAuth(user, password)
return m_auth_obj
#------------------------------------------------------------------------------
示例8: test_proxies_param_with_ntlm
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def test_proxies_param_with_ntlm(self):
"""Test proxies with NTLM credentials."""
urls = {'http': 'localhost:8080', 'https': 'localhost:8080'}
proxies_with_ntlm_dict = {
'urls': urls,
'username_ntlm': 'domain\\username',
'password_ntlm': 'password'
}
ntlm_expected_result = {
'verify': True,
'proxies': urls,
'auth': HttpNtlmAuth('domain\\username', 'password')
}
proxies_with_ntlm_credentials = Credentials(
'dummy_token', 'https://dummy_url', proxies=proxies_with_ntlm_dict)
result = proxies_with_ntlm_credentials.connection_parameters()
# Verify the NTLM credentials.
self.assertEqual(
ntlm_expected_result['auth'].username, result['auth'].username)
self.assertEqual(
ntlm_expected_result['auth'].password, result['auth'].password)
# Remove the HttpNtlmAuth objects for direct comparison of the dicts.
ntlm_expected_result.pop('auth')
result.pop('auth')
self.assertDictEqual(ntlm_expected_result, result)
示例9: auth
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def auth(self, username, password):
log = logging.getLogger(f"auth_owa({username})")
headers = {"Content-Type": "text/xml"}
r = requests.get(self.autodiscover_url, auth=HttpNtlmAuth(username, password), verify=False)
if r.status_code == 200:
log.info(print_good(f"Found credentials: {username}:{password}"))
self.valid_accounts.add(f'{username}:{password}')
else:
log.info(print_bad(f"Authentication failed: {username}:{password} (Invalid credentials)"))
示例10: __init__
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def __init__(self, username, password):
"""
Provides NTLM authentication (intended for SharePoint On-Premises)
Note: due to Outlook REST API v1.0 BasicAuth Deprecation
(refer https://developer.microsoft.com/en-us/office/blogs/outlook-rest-api-v1-0-basicauth-deprecation/)
NetworkCredentialContext class should be no longer utilized for Outlook REST API v1.0
:type username: str
:type password: str
"""
super(NTLMAuthenticationContext, self).__init__(username, password)
self.auth = HttpNtlmAuth(*self.userCredentials)
示例11: set_auth
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def set_auth(self):
user = self.config.get(section='CREDENTIALS', option='NtlmUser', fallback=None)
password = self.config.get(section='CREDENTIALS', option='NtlmPassword', fallback=None)
return HttpNtlmAuth(user, password) if user is not None and password is not None else None
示例12: create_ntlm_auth
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def create_ntlm_auth(config):
global requests_ntlm
if requests_ntlm is None:
import requests_ntlm
return requests_ntlm.HttpNtlmAuth(config['ntlm_domain'], config['password'])
示例13: test_config_ntlm
# 需要导入模块: import requests_ntlm [as 别名]
# 或者: from requests_ntlm import HttpNtlmAuth [as 别名]
def test_config_ntlm(self):
instance = {'auth_type': 'ntlm', 'ntlm_domain': 'domain\\user', 'password': 'pass'}
init_config = {}
# Trigger lazy import
http = RequestsWrapper(instance, init_config)
assert isinstance(http.options['auth'], requests_ntlm.HttpNtlmAuth)
with mock.patch('datadog_checks.base.utils.http.requests_ntlm.HttpNtlmAuth') as m:
RequestsWrapper(instance, init_config)
m.assert_called_once_with('domain\\user', 'pass')