如何通过在Python的REST API访问SharePoint网站? [英] How to access a sharepoint site via the REST API in Python?
问题描述
我在SharePoint 2013以下的网站在我的本地VM:
I have the following site in SharePoint 2013 in my local VM:
的http://共赢5a8pp4v402g / sharepoint_test / site_1 /
当我访问该从浏览器,它会提示我的用户名和密码,然后正常工作。但是我想使用Python中的REST API做同样的。我使用的是请求库,这是我做了什么:
When I access this from the browser, it prompts me for the username and password and then works fine. However I am trying to do the same using the REST API in Python. I am using the requests library, and this is what I have done:
import requests
from requests.auth import HTTPBasicAuth
USERNAME = "Administrator"
PASSWORD = "password"
response = requests.get("http://win-5a8pp4v402g/sharepoint_test/site_1/", auth=HTTPBasicAuth(USERNAME, PASSWORD))
print response.status_code
不过,我得到一个401我不明白。我缺少什么?
However I get a 401. I dont understand. What am I missing?
注:我跟着这篇文章 HTTP ://tech.bool.se/using-python-to-request-data-from-sharepoint-via-rest/
推荐答案
这可能是因为您的SharePoint站点使用不同的身份验证方案。您可以通过检查在Firebug或Chrome开发人员工具对网络流量进行检查。
It's possible that your SharePoint site uses a different authentication scheme. You can check this by inspecting the network traffic in Firebug or the Chrome Developer Tools.
幸运的是,请求库支持多种身份验证选项:<一个href=\"http://docs.python-requests.org/en/latest/user/authentication/\">http://docs.python-requests.org/en/latest/user/authentication/
Luckily, the requests library supports many authentication options: http://docs.python-requests.org/en/latest/user/authentication/
富勒例如,我需要访问网络的人使用NTLM身份验证。安装请求,NTML 插件后,我能够使用类似于此code来访问网站:
Fore example, one of the networks I needed to access uses NTLM authentication. After installing the requests-ntml plugin, I was able to access the site using code similar to this:
import requests
from requests_ntlm import HttpNtlmAuth
requests.get("http://sharepoint-site.com", auth=HttpNtlmAuth('DOMAIN\\USERNAME','PASSWORD'))
这篇关于如何通过在Python的REST API访问SharePoint网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!