2017-06-13 2 views
0

J'essaie d'obtenir des détails à partir de l'API de repos sharepoint en utilisant get request. Utilisation de Java Je suis en mesure d'obtenir les détails en utilisant des informations d'identification. Cependant lorsque vous essayez de python je reçois 401 erreur Est-il possible d'y accéder sans envoyer des titres de compétenceSharepoint reste api obtenir la demande en utilisant python retourne 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'} 

Répondre

0
from requests_negotiate_sspi import HttpNegotiateAuth 

r=requests.get("https://example", auth=HttpNegotiateAuth(), verify=False) 

Cela devrait le faire.