在Windows上使用python自动化Azure Azcopy [英] Automate azure azcopy using python on windows

查看:97
本文介绍了在Windows上使用python自动化Azure Azcopy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python中的 azcopy 我已经使用过 CLI 中的该工具,并且可以正常工作!

我已经成功执行了以下命令:

上传:

  set AZCOPY_SPA_CLIENT_SECRET =<我的客户机密>azcopy login --service-principal --application-id =< removed>--tenant-id =<已移除>azcopy复制"D:\ azure \ content""https://dummyvalue.blob.core.windows.net/container1/result4" --overwrite = prompt --follow-symlinks --recursive --from-to = LocalBlob--blob-type =检测 

类似地下载

  azcopy复制"https://dummyvalue.blob.core.windows.net/container1/result4""D:\ azure \ azcopy_windows_amd64_10.4.3 \ temp \ result2"-递归 

现在,我想使用python自动化这些命令,我知道azcopy也可以通过SAS密钥使用,但这超出了我的工作范围

第一次尝试:

来自子流程导入调用的

 call([[azcopy],"login",-service-principal",-application-id =< removed>",-tenant-id =< removed>"]) 

第二次尝试:

  import osos.system("azcopy登录--service-principal --application-id =< removed> --tenant-id =< removed>") 

我已经在我的环境中设置了AZCOPY_SPA_CLIENT_SECRET .

我在Windows上使用python 3.

每次我收到此错误:

无法执行登录命令:服务主体auth需要一个应用程序ID和客户端机密/证书

注意:如果您的凭据是在最近5分钟内创建的,请等待几分钟,然后重试.

我不想使用Azure VM来完成这项工作

有人可以帮我解决这个问题吗?

解决方案

这是因为 set cmd不会设置永久环境变量,它仅在当前Windows cmd提示符下生效./p>

您应该通过UI手动设置环境变量,或尝试使用 setx 命令.

我通过使用您的代码进行了测试,并根据用户界面手动设置了 AZCOPY_SPA_CLIENT_SECRET 的环境变量,然后该代码可以正常运行(这可能需要一个几分钟后生效).

测试结果如下:

I am trying to use azcopy from python, I have already used this from CLI and it is working!

I have successfully executted the following commands:

for upload :

set AZCOPY_SPA_CLIENT_SECRET=<my client secret>
azcopy login --service-principal --application-id=<removed> --tenant-id=<removed>
azcopy copy "D:\azure\content" "https://dummyvalue.blob.core.windows.net/container1/result4" --overwrite=prompt --follow-symlinks --recursive --from-to=LocalBlob --blob-type=Detect

Similarly for download

azcopy copy "https://dummyvalue.blob.core.windows.net/container1/result4" "D:\azure\azcopy_windows_amd64_10.4.3\temp\result2" --recursive

Now, I want to automate these commands using python, I know that azcopy can also be used using SAS keys but that is out of scope for my working

First attempt:

from subprocess import call
call(["azcopy", "login", "--service-principal", "--application-id=<removed>", "--tenant-id=<removed>"])

Second attempt:

import os
os.system("azcopy login --service-principal --application-id=<removed> --tenant-id=<removed>")

I have already set AZCOPY_SPA_CLIENT_SECRET in my environment.

I am using python 3 on windows.

Every time I get this error:

Failed to perform login command: service principal auth requires an application ID, and client secret/certificate

NOTE: If your credential was created in the last 5 minutes, please wait a few minutes and try again.

I don't want to use Azure VM to do this job

Could anyone please help me fix this problem?

解决方案

This is because the set cmd does not set a permanent environment variable, it only takes effect in the current windows cmd prompt.

You should manually set the environment variable via UI or try to use setx command.

I did a test by using your code, and manually set the environment variable of AZCOPY_SPA_CLIENT_SECRET as per UI, then the code can run without issues(it may take a few minutes to take effect).

Test result is as below:

这篇关于在Windows上使用python自动化Azure Azcopy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆