簡體   English   中英

無法使用python創建Azure連接服務

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM