python调用接口返回401_使用python的sharepoirestapi get请求返回401

我正在尝试使用get请求从sharepointrestapi获取详细信息。

使用Java,我可以使用任何凭证获取详细信息。

但是当我从python尝试时,我得到401错误

是否可以在不发送凭证的情况下访问它Python Code:

import requests

from requests_ntlm import HttpNtlmAuth

headers = {

"Accept":"application/json; odata=verbose",

"Content-Type":"application/json; odata=verbose",

"odata":"verbose",

"X-RequestForceAuthentication": "true",

"Connection":"Keep-alive",

"Upgrade-Insecure-Requests":'1',

"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

}

auth = HttpNtlmAuth('username','password')

response =requests.get("url", auth=auth)

print("--------",response.request.headers)

for r in response.history:

print ("--------",r.headers)

print(response)

Response:

------- {'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'Ke

ep-Alive', 'User-Agent': 'python-requests/2.17.3', 'Authorization': 'NTLM TlRMTV

NTUAADAAAAGAAYAGYAAAAYABgAfgAAAAIAAgBIAAAADAAMAEoAAAAQABAAVgAAAAAAAACWAAAABYKIog

UBKAoAAAAPLgBhAGMAbgByAGYAcwBMADAAMQA0ADIAMQAxADMAItYC2wYJ7G4AAAAAAAAAAAAAAAAAAA

AA8n1+n9UWFFRUMQzjMj8muwmYNCYfa91n'}

-------- {'X-FRAME-OPTIONS': 'SAMEORIGIN', 'X-Content-Type-Options': 'nosniff',

'Content-Type': 'text/plain; charset=utf-8', 'SPRequestDuration': '3', 'SPIisLat

ency': '0', 'X-Powered-By': 'ASP.NET', 'WWW-Authenticate': 'Negotiate, NTLM', 'X

-MS-InvokeApp': '1; RequireReadOnly', 'Content-Length': '16', 'X-SPWFE': 'W00025

0', 'Date': 'Tue, 13 Jun 2017 10:03:18 GMT', 'SPRequestGuid': '5231fb9d-1eac-002

a-e59e-04fcc12587ee', 'request-id': '5231fb9d-1eac-002a-e59e-04fcc12587ee', 'Mic

rosoftSharePointTeamServices': '15.0.0.4763', 'Server': 'Microsoft-IIS/8.5'}

-------- {'X-FRAME-OPTIONS': 'SAMEORIGIN', 'SPRequestDuration': '1', 'X-Content-

Type-Options': 'nosniff', 'WWW-Authenticate': 'NTLM TlRMTVNTUAACAAAADAAMADgAAAAF

gomiXpOD7CdoaSEAAAAAAAAAALIAsgBEAAAABgOAJQAAAA9DAEcAVQBTAEUAUgACAAwAQwBHAFUAUwBF

AFIAAQAOAFcAMAAwADAAMgA1ADAABAAmAGMAZwB1AHMAZQByAC4AYwBhAHAAZwByAG8AdQBwAC4AYwBv

AG0AAwA2AHcAMAAwADAAMgA1ADAALgBjAGcAdQBzAGUAcgAuAGMAYQBwAGcAcgBvAHUAcAAuAGMAbwBt

AAUAGABjAGEAcABnAHIAbwB1AHAALgBjAG8AbQAHAAgAqlFmSCzk0gEAAAAA, Negotiate', 'SPIis

Latency': '0', 'X-Powered-By': 'ASP.NET', 'MicrosoftSharePointTeamServices': '15

.0.0.4763', 'Content-Length': '0', 'X-SPWFE': 'W000250', 'Date': 'Tue, 13 Jun 20

17 10:03:18 GMT', 'SPRequestGuid': '5231fb9d-0eaf-002a-e59e-0ff3040d6d28', 'requ

est-id': '5231fb9d-0eaf-002a-e59e-0ff3040d6d28', 'X-MS-InvokeApp': '1; RequireRe

adOnly', 'Server': 'Microsoft-IIS/8.5'}

你可能感兴趣的:(python调用接口返回401)