使用Windows身份验证访问Python中的Sharepoint网站 [英] Accessing sharepoint site in python with windows authentication
问题描述
我正在尝试使用Windows身份验证的Sharepoint网站.我可以使用requests
模块访问该站点,但需要我明确声明Windows密码.
I am trying to work with a sharepoint site that use my windows authentication. I can use the requests
module to access the site but it requires I explicitly state my windows password.
import requests
from requests_ntlm import HttpNtlmAuth
SITE = "https://sharepointsite.com/"
PASSWORD = "pw"
USERNAME = "domain\\user"
response = requests.get(SITE, auth=HttpNtlmAuth(USERNAME,PASSWORD))
print response.status_code
Python是否可以通过Windows身份验证访问该站点,所以我不必提供密码?似乎可以通过requests_nltm
做到这一点,但我无法解决.
Is there a way for Python to access the site through windows authentication so I don't have to provide my password? It seems like this might be possible through requests_nltm
but I can't work out how.
推荐答案
If you don't want to explicitly state your windows password you could use the getpass
module:
import requests
from requests_ntlm import HttpNtlmAuth
import getpass
SITE = "https://sharepointsite.com/"
USERNAME = "domain\\user"
response = requests.get(SITE, auth=HttpNtlmAuth(USERNAME, getpass.getpass()))
print response.status_code
通过这种方式,您不必以纯文本格式存储密码.
This way you don't have to store you password in plain text.
查看HttpNtlmAuth
Looking at the code for the requests_ntlm
there isn't a way to use it without supplying your password or the hash of your password to HttpNtlmAuth
这篇关于使用Windows身份验证访问Python中的Sharepoint网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!