My goal is to access the odata-api of MS-project (online = cloud-version) in python. The api is accessible under:
https://mycompany.sharepoint.com/sites/myprojectinstance/_api/ProjectData/
My active-directory-user has the rights to access the ms-project-instance and the odata-api: I can access the data using a webbrowser (being logged in to my microsoft-account) and in Power-BI. In following a part of the successfull request:
service xml:base="https://mycompany.sharepoint.com/sites/myprojectinstance/_api/ProjectData/">
<workspace>
<atom:title>Default</atom:title>
<collection href="Projekte">
<atom:title>Projekte</atom:title>
</collection>
But what I want to do is writing a python script to access the odata-feed. The problem: authentication isn't working using basic-auth oder ntlm-auth. Here is my ntlm example:
import json
import requests
from requests_ntlm import HttpNtlmAuth
# Set the API endpoint URL
ms_project_api_url = 'https://mycompany.sharepoint.com/sites/myprojectinstance/_api/ProjectData/'
with open('../secrets.json') as f:
secrets = json.load(f)
response = requests.get(ms_project_api_url, auth=HttpNtlmAuth(secrets['username'], secrets['password']))
For the username I tried different syntax: prename.lastname, domain\prename.lastname, domain\prename.lastname@company.de etc.
I always get an:
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2147024891, System.UnauthorizedAccessException</m:code>
<m:message xml:lang="de-DE">Attempted to perform an unauthorized operation.</m:message
</m:error>
I know that it would propably work using the microsoft authentication library for python, but I want to find a way without registering an App in Azure Portal. During my research I found a post regarding postman using the app-registration, but no (working) solution on how to use ntlm-auth. How can I get the ntlm-auth to work?