使用请求访问url时处理Windows身份验证 [英] Handling windows authentication while accessing url using requests
本文介绍了使用请求访问url时处理Windows身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了Python请求库来访问SOAP请求。它运行得很好。因为我们的域结构发生了变化。我无法访问URL,它总是提示我输入凭据。
我正在使用以下代码访问以前使用请求的URL。
program_list_response = requests.get(program_list_path,
data=self.body, headers=self.headers)
如何使用请求在后台通过身份验证?
推荐答案
您可以使用Authentication功能来提供要访问的链接的凭据。
例如:
您可以使用以下格式传递用户名和密码:
requests.get('https://website.com/user', auth=('user', 'pass'))
有关更多详细信息,我建议使用official docs。
对于处理Windows身份验证,我建议使用Requests-NTLM。
例如:
import requests
from requests_ntlm import HttpNtlmAuth
requests.get("http://ntlm_protected_site.com",auth=HttpNtlmAuth('domain\username','password'))
这篇关于使用请求访问url时处理Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文