Power BI Rest API AADSTS50034:XXXXX目录中不存在用户帐户{EmailHidden}

2024-04-20 01:37:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取访问令牌,而不是获取此错误消息

AdalError: Get Token request returned http error: 400 and server response: {"error":"invalid_grant","error_description":"AADSTS50034: The user account {EmailHidden} does not exist in the XXXXX directory. To sign into this application, the account must be added to the directory.\r\nTrace ID: f18021a8-b10a-40bf-9f0a-7975b38e2300\r\nCorrelation ID: 4f61c8f5-ed06-41f1-8d7b-756dd7c09e10\r\nTimestamp: 2020-12-16 03:27:49Z","error_codes":[50034],"timestamp":"2020-12-16 03:27:49Z","trace_id":"f18021a8-b10a-40bf-9f0a-7975b38e2300","correlation_id":"4f61c8f5-ed06-41f1-8d7b-756dd7c09e10","error_uri":"https://login.windows.net/error?code=50034"}

我的python代码

import adal
import json
import pyodbc
import requests

AUTHORITY_URL = 'https://login.windows.net/XXXXX'
RESOURCE = 'https://analysis.windows.net/powerbi/api'
CLIENT_ID = 'XXXXX'
userid='nurdin@xxxxx.com.my'
userpassword='xxxxx'
completedtime = []
verify = []

def make_headers(access_token):
    return {
    'Authorization': 'Bearer {}'.format(access_token)
    }

context = adal.AuthenticationContext(AUTHORITY_URL)
token = context.acquire_token_with_username_password(RESOURCE,userid,userpassword,CLIENT_ID)
access_token = token['accessToken']
print(access_token)

Tags: thehttpsimporttokenidnetaccesswindows
1条回答
网友
1楼 · 发布于 2024-04-20 01:37:38

您的代码在我这方面运行良好,请确保您的工作帐户位于AUTHORITY_URL中的租户之下,如果不是,您可以按照此link创建一个新用户,而不启用MFA

import adal

AUTHORITY_URL = 'https://login.windows.net/<tenant-id>'
RESOURCE = 'https://analysis.windows.net/powerbi/api'
CLIENT_ID = '<client-id>'
userid='username@tenantname.onmicrosoft.com'
userpassword='xxxxxx'

context = adal.AuthenticationContext(AUTHORITY_URL)
token = context.acquire_token_with_username_password(RESOURCE,userid,userpassword,CLIENT_ID)
access_token = token['accessToken']
print(access_token)

enter image description here

相关问题 更多 >