我正在尝试按照以下Azure文档更新(发布)数据分区:https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-async-refresh

无论是发布还是获取我都会得到401未经授权(即使服务关闭!)。

我从azure AD(ServicePrincipalCredential)获得了令牌。
我将AD添加为Analysis Services管理员(https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-server-admins
我将所有者角色授予Analysis Services IAM中的AD。

它与具有相同身份验证的Analysis Services管理rest api(https://docs.microsoft.com/en-us/rest/api/analysisservices/operations/list)一起使用(响应码200)

我的python代码:

from azure.common.credentials import ServicePrincipalCredentials
import requests

credentials = ServicePrincipalCredentials(client_id="ad_client_id",
                                          secret="ad_secret",
                                          tenant="ad_tenant")
token = credentials.token

url = "https://westeurope.asazure.windows.net/servers/{my_server}/models/{my_model}/refreshes"

test_refresh = {
            "Type": "Full",
            "CommitMode": "transactional",
            "MaxParallelism": 1,
            "RetryCount": 1,
            "Objects": [
                {
                    "table": "my_table",
                    "partition": "my_partition"
                }
            ]
        }

header={'Content-Type':'application/json', 'Authorization': "Bearer {}".format(token['access_token'])}

r = requests.post(url=url, headers=header, data=test_refresh)

import json
print(json.dumps(r.json(), indent=" "))


我得到的回应:

{
 "code": "Unauthorized",
 "subCode": 0,
 "message": "Authentication failed.",
 "timeStamp": "2019-05-22T13:39:03.0322998Z",
 "httpStatusCode": 401,
 "details": [
  {
   "code": "RootActivityId",
   "message": "aab22348-9ba7-42c9-a317-fbc231832f75"
  }
 ]
}


我无可救药,能否请您帮我一些忙,使事情变得清晰起来?

最佳答案

您的令牌很可能不正确。

您是否尝试过验证令牌?使用类似http://calebb.net/的名称

我看到一些ServicePrincipalCredentials的示例,它们规定了这样的上下文或资源:

credentials = ServicePrincipalCredentials(
    tenant=options['tenant_id'],
    client_id=options['script_service_principal_client_id'],
    secret=options['script_service_principal_secret'],
    resource='https://graph.windows.net'


这里的好样本:

https://www.programcreek.com/python/example/103446/azure.common.credentials.ServicePrincipalCredentials

我认为解决方案是尝试更多有意义的事情并遵循错误详细信息。

关于python - Azure Analysis rest api:401未经授权。 “验证失败。”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56258357/

10-12 20:06