[英]Can't create azure linked service with python
我想做什么
我正在尝试创建一个蔚蓝的数据工厂管道,以将文件从blob复制并粘贴到blob或从blob复制并粘贴到数据湖。
我做了什么
我只是按照Microsoft网站上的教程进行操作,我已经有一个ADF和Blob,所以我不再创建它,我现在正尝试创建一个Azure链接服务,所以我使用了以下代码:
# Create an Azure Storage linked service
ls_name = 'storageLinkedService'
# IMPORTANT: specify the name and key of your Azure Storage account.
storage_string = SecureString('DefaultEndpointsProtocol=https;AccountName=<storageaccountname>;AccountKey=<storageaccountkey>')
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)
print_item(ls)
但是当我运行它时,我得到了这个错误:
Traceback (most recent call last):
File "<ipython-input-173-cabc65dd11b9>", line 4, in <module>
ls = adf_client.linked_services.create_or_update(rg_name, df_name, ls_name, ls_azure_storage)
File "C:\ProgramData\Anaconda3\lib\site-packages\azure\mgmt\datafactory\operations\linked_services_operations.py", line 170, in create_or_update
raise models.ErrorResponseException(self._deserialize, response)
ErrorResponseException: Operation returned an invalid status code 'Not Found'
我不知道为什么会收到此错误。 有人有主意吗?
更新资料
我试图跳过此步骤,并尝试使用以下命令在blob中创建和归档: adf_client.datasets.create_or_update(rg_name, df_name, ds_name, ds_azure_blob)
我遇到了相同的错误ErrorResponseException: Operation returned an invalid status code 'Not Found'
,这使我认为问题可能与Blob有关。
我试图重现您的问题,但失败了。
我没有ADF,因此我按照官方教程创建了Data Factory和Linked服务,没有发生错误。
主功能
def main():
# Azure subscription ID
subscription_id = '***'
# This program creates this resource group. If it's an existing resource group, comment out the code that creates the resource group
rg_name = '***'
# The data factory name. It must be globally unique.
df_name = '***'
# Specify your Active Directory client ID, client secret, and tenant ID
credentials = ServicePrincipalCredentials(client_id='***', secret='***', tenant='***')
resource_client = ResourceManagementClient(credentials, subscription_id)
adf_client = DataFactoryManagementClient(credentials, subscription_id)
rg_params = {'location':'eastus'}
df_params = {'location':'eastus'}
# create the resource group
# comment out if the resource group already exits
resource_client.resource_groups.create_or_update(rg_name, rg_params)
Create a data factory
df_resource = Factory(location='eastus')
df = adf_client.factories.create_or_update(rg_name, df_name, df_resource)
print_item(df)
while df.provisioning_state != 'Succeeded':
df = adf_client.factories.get(rg_name, df_name)
time.sleep(1)
# Create an Azure Storage linked service
ls_name = 'storageLinkedService'
# IMPORTANT: specify the name and key of your Azure Storage account.
storage_string = SecureString('DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***')
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)
print_item(ls)
ErrorResponseException:操作返回了无效的状态码“未找到”
我认为您可以检查参数是否有误或服务是否存在。(df,资源组,存储帐户)
如有任何疑问,请随时告诉我。
更新答案:
我在门户上的Azure AD中创建了自己的应用程序注册。
如下的应用程序ID是您的client_id
创建您的secret
并记住将其写下来,因为它将在以后隐藏。
如下所示的目录ID是tenant ID
更新答案2:
我也是贡献者角色,所以我认为这不是角色问题。 我试图将参数中的ra_name(resource group)更改为不存在的值,成功重现了您的异常。
请再次检查您的资源组或其他参数是否存在。
仅供参考:
似乎ADF V1和V2当前不支持西欧地区。
然而,这在支持区域的章节文章尚未更新。 这么久困扰着你。 您可以重新创建ADF并按照原始代码创建链接服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.