當前位置: 首頁>>代碼示例>>Python>>正文


Python requests_ntlm.HttpNtlmAuth方法代碼示例

本文整理匯總了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() 
開發者ID:flipkart-incubator,項目名稱:watchdog,代碼行數:19,代碼來源:HTTP.py

示例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() 
開發者ID:penetrate2hack,項目名稱:ITWSV,代碼行數:20,代碼來源:crawler.py

示例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 
開發者ID:Qiskit,項目名稱:qiskit-ibmq-provider,代碼行數:25,代碼來源:credentials.py

示例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 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:19,代碼來源:test_http.py

示例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 
開發者ID:rapid7,項目名稱:insightconnect-plugins,代碼行數:8,代碼來源:api.py

示例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"]
        ) 
開發者ID:httprunner,項目名稱:httprunner,代碼行數:10,代碼來源:debugtalk.py

示例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


#------------------------------------------------------------------------------ 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:40,代碼來源:web_utils.py

示例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) 
開發者ID:Qiskit,項目名稱:qiskit-ibmq-provider,代碼行數:29,代碼來源:test_registration.py

示例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)")) 
開發者ID:byt3bl33d3r,項目名稱:SprayingToolkit,代碼行數:12,代碼來源:owa.py

示例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) 
開發者ID:vgrem,項目名稱:Office365-REST-Python-Client,代碼行數:15,代碼來源:ntlm_authentication_context.py

示例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 
開發者ID:geometalab,項目名稱:OSMDeepOD,代碼行數:6,代碼來源:wms_api.py

示例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']) 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:8,代碼來源:http.py

示例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') 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:14,代碼來源:test_http.py


注:本文中的requests_ntlm.HttpNtlmAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。