Python Graph SDK's GraphServiceClient's me.todo.lists.get() results in 401 APIError with no additional details

Thomas Dattilo 0 Reputation points
2024-07-10T21:03:08.72+00:00

Starting off on a personal project, I'm able to successfully create an app in the Azure AD portal and am able to log in using the Python flow described in https://learn.microsoft.com/en-us/graph/tutorials/python?tabs=aad&tutorial-step=3, but am unable to then use the GraphServiceClient's me.todo.lists.get() to list the tasks in my To-Do account. The result is a 401 APIError with message: None, error: MainError(additional_data={}, code='UnknownError', details=None, inner_error=InnerError(additional_data={}, etc, essentially containing no data beyond the datetime I made the call and the request ID. This is a delegated process (by my understanding), and I have Tasks.ReadWrite in my scope (and this did appear in the DynamicConsent dialogue as well). Where else should I look to debug this? The code is literally just:

self.device_code_credential = DeviceCodeCredential(client_id, tenant_id=tenant_id); self.user_client = GraphServiceClient(self.device_code_credential, self.graph_scopes); await self.user_client.me.todo.lists.get()

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,343 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 39,746 Reputation points
    2024-07-16T07:57:23.3066667+00:00

    Hi Thomas Dattilo,

    It works fine for me. Try to log in your user into Graph Explorer and call this endpoint. If it works, copy the token generated in Graph Explorer and decode it and compare it with your token to check if they are any different.

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments