Azure ADLS - Python 内的 azcopy 复制

发布于 2025-01-12 12:08:14 字数 835 浏览 3 评论 0原文

我无权获取容器的访问密钥。因此无法使用“azure.storage.blob import BlobServiceClient”。我只能使用使用 SAS 密钥的 ContainerClient 类。

我可以在 Windows 计算机的命令提示符下使用“azure azcopy”复制包括子文件夹在内的数据。 子文件夹:456 并使用以下命令将数据复制到目标 adls 容器。

azcopy 复制“https://[account].blob.core.windows.net/[source_container]/abc/def/123/tst/456?[SAS]”“https://[account].blob.core。 windows.net/[target_container]/tgttst?[SAS]"

请让我知道如何自动在目标 ADLS 上创建子文件夹并在 Python 脚本内复制数据。

提前致谢。

收到错误消息“属性错误:‘BlobClient’对象没有属性 create_container”

    from azure.storage.blob import ContainerClient 
    sas_url="[account].blob.core.windows.net/[target_container]/tgttst?[SAS]"  
container=ContainerClient.from_container_url(sas_url) 
container_client = container.get_blob_client("abc/def/123") 
container_client.create_container()

注意:SAS 令牌具有读/写/列表权限

I don't have permission to get access keys for containers.Due to this unable to use "azure.storage.blob import BlobServiceClient".I can use only ContainerClient class using SAS key.

I can copy data including subfolder using "azure azcopy" on the command prompt from a windows machine.
subfolder:456 and data copied to target adls container using below command.

azcopy copy "https://[account].blob.core.windows.net/[source_container]/abc/def/123/tst/456?[SAS]" "https://[account].blob.core.windows.net/[target_container]/tgttst?[SAS]"

Please let me know how to automate to create subfolder on target ADLS and to copy data inside Python script.

Thanks in advance.

getting an error message "Attribute Error: 'BlobClient' object has no attribute create_container"

    from azure.storage.blob import ContainerClient 
    sas_url="[account].blob.core.windows.net/[target_container]/tgttst?[SAS]"  
container=ContainerClient.from_container_url(sas_url) 
container_client = container.get_blob_client("abc/def/123") 
container_client.create_container()

Note : SAS token has READ/WRITE/LIST privileges

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2025-01-19 12:08:14

我已经找到解决办法了,感谢您的帮助:

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

def azure_connect_sas_url(source_container_sas_url, source_container_name):
    try:
        blob_source_service_client = BlobServiceClient(source_container_sas_url)
        source_container_client = blob_source_service_client.get_container_client(source_container_name)
        print ("SAS URL -- Connected.")
        return source_container_client

    except Exception as ex:
        print ("Error: " + str(ex))

def main():
    try:
        azure_sas_url = input ('Please enter SAS URL: ')
        container_name = input ('Please enter Container name: ')

        ## SAS URL
        connection_instance = azure_connect_sas_url(azure_sas_url, container_name)

        print ('Done')
        
    except Exception as ex:
        print ('main | Error: ', ex)

if __name__ == "__main__":
    main()

I have found the solution, thanks for your help:

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

def azure_connect_sas_url(source_container_sas_url, source_container_name):
    try:
        blob_source_service_client = BlobServiceClient(source_container_sas_url)
        source_container_client = blob_source_service_client.get_container_client(source_container_name)
        print ("SAS URL -- Connected.")
        return source_container_client

    except Exception as ex:
        print ("Error: " + str(ex))

def main():
    try:
        azure_sas_url = input ('Please enter SAS URL: ')
        container_name = input ('Please enter Container name: ')

        ## SAS URL
        connection_instance = azure_connect_sas_url(azure_sas_url, container_name)

        print ('Done')
        
    except Exception as ex:
        print ('main | Error: ', ex)

if __name__ == "__main__":
    main()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文