I'm trying to pull down the office 365 Usage analytics as an Odata object in Python, so I can set up an automated task to store the data. The process is described here https://learn.microsoft.com/en-US/microsoft-365/admin/usage-analytics/enable-usage-analytics?view=o365-worldwide for viewing this inside of Power BI. But the data provided is only for the last month and we want to see cumulative data for the last 2 years. I've written some Python code that can pull down the Odata object, but I'm having some issues determining if the data is blank because of an authentication error, or I just don't know where to look. I haven't been able to find much info on this, any help would be appreciated. especially if there's a way for me to save this object as a file and view it in some external program I don't know about. Here's the code I have, you can try it for yourself if you go to the 365 admin portal and plug in your Tenant ID, username, and password.
import requests
import pyodata
import json
import settings
SERVICE_URL = 'https://reports.office.com/pbi/v1.0/' + settings.TennantID
# Create instance of OData client
session = requests.Session()
session.auth = (settings.username, settings.password)
client = pyodata.Client(SERVICE_URL, session)
EntitySets = client.entity_sets._entity_sets['TenantClientUsage']
data = EntitySets.get_entities()
print('debug here')