Share via

Python REST API Sharepoint. Error - "'error': 'invalid_request', 'error_description': "AADSTS900023: Specified tenant identifier 'tenant_id' is neither a valid DNS name, nor a valid external domain."

Anonymous
2023-08-01T09:25:24+00:00

This is the code which I tried, I am hiding the critical info with 'xxx'

client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'

client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

tenant = 'xxx'

tenant_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

client_id = client_id + '@' + tenant_id

data = { 'grant_type':'client_credentials', 'resource': "00000003-0000-0ff1-ce00-000000000000/" + tenant + "xxx.sharepoint.com@" + tenant_id, 'client_id': client_id, 'client_secret': client_secret,}

headers = { 'Content-Type':'application/x-www-form-urlencoded' }

url = "https://accounts.accesscontrol.windows.net/tenant_id/tokens/OAuth/2" r = requests.post(url, data=data, headers=headers) json_data = json.loads(r.text) print(json_data)

Can anyone guide me on this. This is the first time I am doing this. Have no clue how to debug it and what is causing this error.

This is the error message.

{'error': 'invalid_request', 'error_description': "AADSTS900023: Specified tenant identifier 'tenant_id' is neither a valid DNS name, nor a valid external domain.\r\nTrace ID: 20f02c71-c802-467a-a3fe-0b45a08e4c00\r\nCorrelation ID: 03f90547-f507-4595-85a6-003c6e658171\r\nTimestamp: 2023-08-01 09:09:56Z", 'error_codes': [900023], 'timestamp': '2023-08-01 09:09:56Z', 'trace_id': '20f02c71-c802-467a-a3fe-0b45a08e4c00', 'correlation_id': '03f90547-f507-4595-85a6-003c6e658171', 'error_uri': 'https://accounts.accesscontrol.windows.net/error?code=900023'}
Microsoft 365 and Office | SharePoint | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-08-01T11:12:48+00:00

    Dear Jenifa Thomas,

    Good day! Thank you for your reply to Microsoft Community. We are happy to help you.

    Its seems like this issue related to developer side, you may consider to visit ourcommunity:SharePoint Developmentand this is the most efficient way to report such issue

    https://learn.microsoft.com/en-us/answers/tags/336/office-sp-development

    At the same time, from the error, it looks like the "tenant_id" you entered is incorrect. You can get the correct tenant_ ID from Azure AD (Microsoft - Microsoft Entra admin center)

    Appreciate your understanding.

    Have a good day!

    Best regards,

    1 person found this answer helpful.
    0 comments No comments