Fei Xue set me on the right track. My code requested a resource that ADAL did not expect.
Turns adal.acquire_token_with_username_password in __init__.py has default values (see bottom of the code in class _DefaultValues ) for client_id and resource .
The default ADAL resource is https://management.core.windows.net/ , which was expected by my file_url resource. invalid audience was https://tenant.sharepoint.com .
So, I changed the default ADAL values:
`client_id` = my Azure AD app client_id `resource` = `https://tenant.sharepoint.com/`
ADAL acquire_token_with_username_password (see below) has client_id and resource set to None . I have not tried, but I think they can be edited to remove =None and set in my code instead of class _DefaultValues .
def acquire_token_with_username_password( authority, username, password, client_id=None, resource=None, validate_authority=True ):
And also made a minor (but mandatory) change to my file_url (url to filename) to:
file_url = 'https://pokrant.sharepoint.com/_api/v2.0/drive/root:/analytics/output_analytics.csv:/content'
Now, when I run the code, I get the contents of the csv content printed on the console.
source share