3

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')

1 Answers1

0

the script from the brief look looks OK, but with possible networking problems, you need to investigate the HTTP Requests and Responses, which are handled by the requestslibrary.

If there was authentication error, you would see it in the console just after the client = pyodata.Client(SERVICE_URL, session) line - where is already initial requests for $metadata of the service to build the pyodata object model.

These links should help you to see the actual HTTP traffic under the pyodata hood:

But the main cause of problems seems to be this: you are trying to use Odata V4 service, while pyodata at the moment supports V2 only (support for V4 is filled as enhancement). If you could work with nodejs instead of python, you can use now our sister client library, which supports both odata V2 and V4 - https://github.com/SAP/odata-library/

https://reports.office.com/pbi/v1.0/%20odata/$metadata

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">