[英]Can't create azure linked service with python
What I'm trying to do 我想做什么
I'm trying to create an azure data factory pipeline to copy and paste file from a blob to a blob or from a blob to a data lake. 我正在尝试创建一个蔚蓝的数据工厂管道,以将文件从blob复制并粘贴到blob或从blob复制并粘贴到数据湖。
What i did 我做了什么
I just followed the tutorial on Microsoft's website, i already have an ADF and blob so i didn't create it again, i'm now trying to create an Azure linked service, so i used this code: 我只是按照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)
But when i run it, i obtain this error: 但是当我运行它时,我得到了这个错误:
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'
I don't know why do i get this error. 我不知道为什么会收到此错误。 Does anyone have an idea ?
有人有主意吗?
Update 更新资料
I tried to skip this step and tried to create and file in the blob with this command: adf_client.datasets.create_or_update(rg_name, df_name, ds_name, ds_azure_blob)
我试图跳过此步骤,并尝试使用以下命令在blob中创建和归档:
adf_client.datasets.create_or_update(rg_name, df_name, ds_name, ds_azure_blob)
I got the same error ErrorResponseException: Operation returned an invalid status code 'Not Found'
which lead me to think that the problem is related to the blob maybe. 我遇到了相同的错误
ErrorResponseException: Operation returned an invalid status code 'Not Found'
,这使我认为问题可能与Blob有关。
I tried to reproduce your issue but failed. 我试图重现您的问题,但失败了。
I do not have an ADF so I followed the official tutorial to create Data Factory and Linked service, no error occurred. 我没有ADF,因此我按照官方教程创建了Data Factory和Linked服务,没有发生错误。
main function 主功能
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: Operation returned an invalid status code 'Not Found'
ErrorResponseException:操作返回了无效的状态码“未找到”
I think you could check the arguments if you have a mistake in it or if the service exists.(df,resource group, storage account) 我认为您可以检查参数是否有误或服务是否存在。(df,资源组,存储帐户)
Any concern ,please feel free to let me know. 如有任何疑问,请随时告诉我。
Update Answer: 更新答案:
I created my own application registration in Azure AD on portal. 我在门户上的Azure AD中创建了自己的应用程序注册。
Application ID as below is your client_id
如下的应用程序ID是您的
client_id
Create your secret
and remember to write it down because it will hide later. 创建您的
secret
并记住将其写下来,因为它将在以后隐藏。
Directory Id as below is tenant ID
如下所示的目录ID是
tenant ID
Update Answer 2: 更新答案2:
I'm also a contributor role, so I think it's not a role issue. 我也是贡献者角色,所以我认为这不是角色问题。 I tried to change the ra_name(resource group) in the parameter to a nonexistent value, reproduced your exception successfully .
我试图将参数中的ra_name(resource group)更改为不存在的值,成功重现了您的异常。
Please check again if your resource group or other parameters exist. 请再次检查您的资源组或其他参数是否存在。
Just for summary: 仅供参考:
It seems that ADF V1 and V2 does not support West Europe Region currently. 似乎ADF V1和V2当前不支持西欧地区。
However , the Supported regions chapters in this article have not been updated. 然而,这在支持区域的章节文章尚未更新。 That bothers you so long.
这么久困扰着你。 You could re-create ADF and follow your original code to create link service.
您可以重新创建ADF并按照原始代码创建链接服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.