Azure ADLS-Python内部的azcopy副本



我没有获取容器访问密钥的权限。由于这一点;azure.storage.blob导入blob服务客户端";。我只能使用使用SAS密钥的ContainerClient类。

我可以使用";azure azcopy";在windows机器的命令提示符下。子文件夹:456和使用以下命令复制到目标adls容器的数据。

azcopy副本";https://[account].bob.core.windows.net/[source_container]/abc/def/123/tst/456?[SAS]"https://[account].bob.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令牌具有读/写/列表权限

我找到了解决方案,感谢您的帮助:

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()

最新更新