Error 400 when trying to extract data from sharepoint

Viewed 60

I am trying to extract xml data from a SharePoint site. I always get error 400. Here is my Python code.

import requests
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.http.request_options import RequestOptions
from office365.runtime.client_request import ClientRequest
from office365.graph.graph_client import GraphClient

app_settings = {
    'url': 'https://xxxxxxxx.sharepoint.com/sites/xxxxxxx',
    'client_id': 'xxxxxxx',
    'client_secret': 'xxxxxxxx',
}

context_auth = AuthenticationContext(url=app_settings['url'])
context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])
ctx = ClientContext(app_settings['url'], context_auth)
token = context_auth.provider.token.accessToken


headers = {"Authorization": "Bearer " + token, "Content-type": "application/xml"}
request = requests.get("https://xxxxxxx.sharepoint.com/sites/xxxxxxx/_api/xxxxxx/xxxxx/xxxxx", headers=headers)

I don't understand what I am missing because my url seems to be correct, I can get a token, which seems to be valid and not expired. Moreover, the application I have created on the SharePoint site seems also to be correct. I have entered this code in the permission request XML:

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>

The strange thing is that I can access the lists and subsites data that is available on the SharePoint site, but not this background odata.

Can someone help me please?

0 Answers
Related