Unable to retrieve tenant service info.

Aman 0 Reputation points
2023-03-27T23:43:25.6433333+00:00

I am trying to get a lost of files from my onedrive using a python script but it's giving an error and I am using Application permissions only but it is giving an error while getting access token.

Here is my code-

import requests
import json
# Define the necessary variables
client_id = 'my client id'
client_secret = 'my client secret'
tenant_id = 'my tenant id'
# Get an access token using application permission
url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
data = {'grant_type': 'client_credentials','client_id': client_id,'client_secret': client_secret,    'scope': 'https://graph.microsoft.com/.default'}
response = requests.post(url, data=data)
access_token = json.loads(response.text)['access_token']
print(access_token)

# Get the list of files in the root directory
url = 'https://graph.microsoft.com/v1.0/drive/root/children'
headers = {'Authorization': f'Bearer {access_token}'}
response = requests.get(url, headers=headers)
print(response.text)
files = json.loads(response.text)['value']
# Print the file names
for file in files:    
print(file['name'])
error-
{'error': {'code': 'BadRequest', 'message': 'Unable to retrieve tenant service info.', 'innerError': {'date': '2023-03-27T23:39:07', 'request-id': 'a04737f4-8614-4841-9a45-1b1dc1d25b16', 'client-request-id': 'a04737f4-8614-4841-9a45-1b1dc1d25b16'}}}

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

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. CarlZhao-MSFT 41,206 Reputation points
    2023-03-28T08:18:08.71+00:00

    Hi @Aman

    This error is usually related to O365 licenses. Before calling the endpoint, make sure your enterprise tenant has an Office 365 license.

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.