[英]Fail to create dataset using azure sdk python for azure data factory
我正在嘗試使用 azure sdk for python 在 ADF 中創建數據集,不幸的是我遇到了此錯誤消息。 我不確定我下面的代碼有什么問題。
dsOut_name = 'POC_DatasetName'
ds_ls ="AzureBlobStorage"
output_blobpath = '/tempdir'
df_name = 'pipeline1'
dsOut_azure_blob = AzureBlobDataset(linked_service_name=ds_ls, folder_path=output_blobpath)
dsOut = adf_client.datasets.create_or_update(rg_name, df_name, dsOut_name, dsOut_azure_blob)
print_item(dsOut)
Error Message: SerializationError: Unable to build a model: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get', DeserializationError: Unable to deserialize to object: type, AttributeError: 'str' object has no attribute 'get'
請幫忙
我可以重現您的問題,這一行ds_ls ="AzureBlobStorage"
是錯誤的,應該是ds_ls = LinkedServiceReference(reference_name=ls_name)
。
您可以參考我的完整工作示例。
確保您的服務主體在數據工廠的Access control (IAM)
中具有 RBAC 角色(例如Owner
、 Contributor
),並且您已完成所有先決條件。
我的包版本:
azure-mgmt-datafactory 0.6.0
azure-mgmt-resource 3.1.0
azure-common 1.1.23
代碼:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.datafactory import DataFactoryManagementClient
from azure.mgmt.datafactory.models import *
subscription_id = '<subscription-id>'
ls_name = 'storageLinkedService'
rg_name = '<group-name>'
df_name = '<datafactory-name>'
credentials = ServicePrincipalCredentials(client_id='<client id of the service principal>',
secret='<secret of the service principal>', tenant='<tenant-id>')
resource_client = ResourceManagementClient(credentials, subscription_id)
adf_client = DataFactoryManagementClient(credentials, subscription_id)
storage_string = SecureString('DefaultEndpointsProtocol=https;AccountName=<storage account name>;AccountKey=<storage account key>')
ls_azure_storage = AzureStorageLinkedService(connection_string=storage_string)
ls = adf_client.linked_services.create_or_update(rg_name, df_name, ls_name, ls_azure_storage)
ds_ls = LinkedServiceReference(reference_name=ls_name)
# Create an Azure blob dataset (output)
dsOut_name = 'ds_out'
output_blobpath = '<container name>/<folder name>'
dsOut_azure_blob = AzureBlobDataset(linked_service_name=ds_ls, folder_path=output_blobpath)
dsOut = adf_client.datasets.create_or_update(rg_name, df_name, dsOut_name, dsOut_azure_blob)
print(dsOut)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.