使用 Windows 身份验证在 python 中访问共享点站点 [英] 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.
推荐答案
如果您不想明确说明您的 Windows 密码,您可以使用 getpass
模块:
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.
查看<代码的代码>requests_ntlm 如果不向 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 中访问共享点站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!