如何使用Python客户机正确验证Kusto?

2024-07-07 07:11:42 发布

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

我正在尝试测试我的节点和azuredataexplorer(ADX/Kusto)之间的连接。我正在考虑使用python脚本在Kusto上创建一个表。在

请注意,我对这些都不是很熟悉,因此下面是详细的步骤。在

我在Microsoft docs上跟踪quickstart guide。在

生成应用程序ID和密钥

使用应用程序注册服务:

  1. 创建新注册(名为kusto test): enter image description here

  2. 创建客户端机密: enter image description here

创建Kusto数据库

从集群中,从UI创建一个数据库(称为kusto test)

enter image description here

授权

在ADX群集上>;“访问控制”(IAM)>;“添加角色分配”。 enter image description here

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])

期望:

  • 在ADX上成功创建表。在

实际:

  • 获取UnauthorizedDatabaseAccessException错误。在
^{pr2}$

Tags: fromtestimportclientiddatastringtable
1条回答
网友
1楼 · 发布于 2024-07-07 07:11:42

在Azure门户“访问控制”中添加所有者只会为该实体提供管理资源的权限(也称为“控制平面”),不适用于对数据库本身(也称为“数据平面”)的权限。在

要提供该应用程序在数据平面中操作的权限,例如运行查询、创建表等。您需要在适用的数据库“权限”部分授予它权限:

database permission section

相关问题 更多 >