【发布时间】:2021-06-07 08:25:58
【问题描述】:
我想使用 Python 使用 Power BI API 端点 update dataflow 重命名 Power BI 租户中的数据流,但我收到授权错误。
按照Microsoft guidance我有:
- 创建 Azure 应用
- 授予
Dataflow.ReadWrite.All权限 - 将服务主体添加到安全组
- 更新了 Power BI 租赁设置以允许新的安全组运行 Power BI API
- 向安全组和服务主体授予对工作区的访问权限
当我运行下面的代码时,我收到了<Response [401]>,但是我为其他端点编写的类似代码,例如get dataflow 或refresh dataflow 工作正常。如果我从 Azure 应用程序中删除所有 Power BI API 权限,它仍然能够运行 get 和 refresh 调用。就像代码正在使用工作区的用户权限而不是获取应用程序权限。
非常感谢任何帮助。
谢谢
Python
import adal
import requests
TENANT_ID = "abc-123"
CLIENT_ID = "def-456"
CLIENT_SECRET = "ghi-789"
WORKSPACE_ID = "jkl-987"
DATAFLOW_ID = "mno-654"
authority_url = "https://login.microsoftonline.com/"+TENANT_ID
context = adal.AuthenticationContext(authority_url)
token = context.acquire_token_with_client_credentials(
resource="https://analysis.windows.net/powerbi/api",
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
)
access_token = token.get("accessToken")
token_type = token.get("tokenType")
tokenString = "{} {}".format(token_type, access_token)
header = {"Authorization": tokenString}
newName = "This is a new name"
body = {"name": newName}
refresh_url = "https://api.powerbi.com/v1.0/myorg/groups/{}/dataflows/{}".format(WORKSPACE_ID, DATAFLOW_ID) #get all meta for specific dataflow
r = requests.patch(url=refresh_url, headers=header, json = body)
print(r)
【问题讨论】:
-
似乎权限
Dataflow.ReadWrite.All是委托类型,但是您在代码中使用client credential 流来获取访问令牌。那么您能否使用username/password flow 在您的代码中获取访问令牌? -
嗨西蒙,有什么更新吗?
-
嗨@HuryShen 感谢您的帮助。我现在尝试使用用户名/密码方法,但得到
AADSTS53003: Access has been blocked by Conditional Access policies.The access policy does not allow token issuance.所以看起来为用户帐户颁发令牌的能力已被我们的租户阻止。我会尝试 acquire_token_with_authorization_code 但我不知道如何获取授权码。 -
请问您的问题是否已解决?如果问题解决了,能否请您将答案标记为“已接受”,提前谢谢。