I'm using Office365-REST-Python-Client to access some files from Sharepoint through a Python script (using App-only method)
a code example would be this:
credentials = ClientCredential(x, y)
ctx = ClientContext(z).with_credentials(credentials)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Web site title: {0}".format(web.properties['Title']))
response = File.open_binary(ctx, relative_url)
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)
print(bytes_file_obj.getvalue())
My problem is that I can get the web.properties (it shows the title in this example) but when I try to do anything related to the file I get an error saying the file does not exist:
b'{"error":{"code":"-2130575338, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The file /PATH/TO/FILE/ does not exist."}}}'
I try creating different files on different locations but the error is the same, some of those would be
z = 'https://tenant.sharepoint.com/sites/test/'
z = 'https://tenant.sharepoint.com/sites/test'
relative_url = '/sites/test/Shared%20Documents/TestBook.xlsx'
relative_url = '/sites/test/Shared Documents/TestBook.xlsx'
relative_url = '/sites/test/SharedDocuments/TestBook.xlsx'
z = 'https://tenant.sharepoint.com/'
z = 'https://tenant.sharepoint.com'
relative_url = '/Shared%20Documents/Book544.xlsx'
relative_url = '/Shared%20Documents/TestTest/TestBook222.xlsx'
relative_url = '/Shared Documents/TestTest/TestBook222.xlsx'
For reference, the paths taken from Sharepoint file properties would be like this: https://tenant.sharepoint.com/Shared%20Documents/Book544.xlsx
https://tenant.sharepoint.com/Shared%20Documents/TestTest/TestBook222.xlsx
https://tenant.sharepoint.com/sites/test/Shared%20Documents/TestBook.xlsx
For this test the xml permissions on /_layouts/15/appinv.aspx are like this (on tenant-admin.sharepoint.com and tenant.sharepoint.com/sites/test respectively):
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
</AppPermissionRequests>
and
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant/sites/test" Right="FullControl" />
</AppPermissionRequests>
I run out of ideas on how to solve this. How can I access the Sharepoint file using the Rest API after I already successfully pass the authentication part?