使用Python Azure CLI将管道变量放入popen命令中

问题描述 投票:0回答:1

我当前的问题是,我正在使用python和HTML创建一个应用程序,以使用HTML表单来收集数据,然后将其转换为Python中的变量,然后使用子流程POPEN将Azure CLI命令发送给Azure租户。当我对命令使用以下代码时,它返回错误。

Python代码

def storageaccountcreate():
    name = request.form['storageaccountname']
    resourcegroup = request.form['resourcegroup']
    subscription = request.form['subscriptionid']
    location = request.form['location']
    sku = request.form['sku']
    command = Popen("az storage account create -n name -g resourcegroup --subscription subscriptionid -l location --sku sku", shell=True ,stdout=subprocess.PIPE)
    text = command.stdout.read().decode("ascii") 
    print(text)
    with open("file.txt","w") as f:
        f.write(text)
    return redirect('/')

错误

Subscription 'subscriptionid' not recognized.
az storage account create: 'sku' is not a valid value for '--sku'. See 'az storage account create --help'.

我可以清楚地知道它正在将其视为纯文本,没有任何变量。如何将变量添加到命令?这是传递给Azure时命令在下面的外观。

az storage account create -n NameVariable -g ResourceGroupVariable --subscription SubscriptionIDVariable -l LocationVariable --sku SkuVariable
python html subprocess
1个回答
0
投票

Format这样的字符串:

© www.soinside.com 2019 - 2024. All rights reserved.