Haz*_*hak 2 python azure azure-data-explorer
我正在尝试测试我的节点和 Azure 数据资源管理器 (ADX/ Kusto) 之间的连接。我正在考虑使用 python 脚本在 Kusto 上创建一个表。
请注意,我对这些都不是很熟悉,因此下面是详细步骤。
我正在关注Microsoft 文档上的此快速入门指南。
生成应用程序 ID 和密钥
使用应用注册服务:
创建 Kusto 数据库
在集群中,从 UI 创建一个数据库(称为 kusto-test)
授权
在 ADX 集群上 > 访问控制 (IAM) > 添加角色分配。

Python脚本
from azure.kusto.data.request import KustoClient, KustoConnectionStringBuilder
from azure.kusto.data.exceptions import KustoServiceError
from azure.kusto.data.helpers import dataframe_from_result_table
KUSTO_DATABASE = "kusto-test"
CLUSTER = "https://mynode.myregion.kusto.windows.net"
CLIENT_ID = "KUSTO_TEST_APP_ID" # From image above
CLIENT_SECRET = "KUSTO_TEST_PASS" # From image above
AUTHORITY_ID = "<insert here your tenant id>" #Got from https://login.windows.net/<YourDomain>/.well-known/openid-configuration/
KCSB_DATA = KustoConnectionStringBuilder.with_aad_application_key_authentication(
CLUSTER, CLIENT_ID, CLIENT_SECRET, AUTHORITY_ID
)
KUSTO_CLIENT = KustoClient(KCSB_DATA)
CREATE_TABLE_COMMAND = ".create table StormEvents (StartTime: datetime, EndTime: datetime, EpisodeId: int, EventId: int, State: string, EventType: string, InjuriesDirect: int, InjuriesIndirect: int, DeathsDirect: int, DeathsIndirect: int, DamageProperty: int, DamageCrops: int, Source: string, BeginLocation: string, EndLocation: string, BeginLat: real, BeginLon: real, EndLat: real, EndLon: real, EpisodeNarrative: string, EventNarrative: string, StormSummary: dynamic)"
RESPONSE = KUSTO_CLIENT.execute_mgmt(KUSTO_DATABASE, CREATE_TABLE_COMMAND)
dataframe_from_result_table(RESPONSE.primary_results[0])
Run Code Online (Sandbox Code Playgroud)
预期的:
实际的:
azure.kusto.data.exceptions.KustoServiceError: (KustoServiceError(...), [{u'error': {u'code': u'Forbidden', u'@permanent': True, u'@message': u"Principal '....' is not authorized to access database 'kusto-test'.", ...}, u'message': u'Caller is not authorized to perform this action', u'@type': u'Kusto.DataNode.Exceptions.UnauthorizedDatabaseAccessException'}}])
Run Code Online (Sandbox Code Playgroud)
在 Azure 门户“访问控制”中添加所有者仅向该实体提供管理资源的权限(也称为“控制平面”),不适用于数据库本身的权限(也称为“数据平面”) ')。
要提供在数据平面中操作的应用程序权限,例如运行查询、创建表等,您需要在适用的数据库“权限”部分授予它权限:
| 归档时间: |
|
| 查看次数: |
1822 次 |
| 最近记录: |