gpt4 book ai didi

带有子进程返回的 Python 脚本必须是 str,而不是 int evrything linter 说是这种情况

转载 作者:太空宇宙 更新时间:2023-11-04 04:40:39 25 4
gpt4 key购买 nike

<分区>

当我运行以下代码时出现以下错误。

版本信息:

Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] on linux

代码:

正确格式位于 https://gist.github.com/Drunkenpanda2000/31f76521ce1166b804a539f40ec21c60

#!/usr/bin/env python

import subprocess

#will be replaced with inputs from Chef

name='test'
vcpus=1
memory=2048
iso='/var/lib/libvirt/images/Centos.iso'
discsize= 80
os_type='linux'
os_variant='centos7'
network_bridge='default'

#setting up the command

args = (
'virt-install' +
' --name=' + name +
' --vcpus=' + vcpus +
' --memory=' + memory +
' --cdrom=' + iso +
' --disk size=' + discsize +
' --os-type=' + os_type +
' --os-varient=' + os_variant +
' --network bridge=' + network_bridge +
" --extra-args 'console=ttyS0,115200n8 serial'" )

#execute the commands in bash

subprocess.call(args, shell=True)

错误

[drunkenpanda@Diablo Scripts]$ ./createvm.py  Traceback (most recent call last):   File "./createvm.py", line 27, in <module>
' --network bridge=' + network_bridge + TypeError: must be str, not int

新代码

    args = ['virt-install',
' --name',name,
' --vcpus',str(vcpus),
' --memory',str(memory),
' --cdrom',iso,
' --disk-size',str(discsize),
' --os-variant',os_variant,
' --os-type',os_type,
' --network bridge',network_bridge]


# " --extra-args 'console=ttyS0,115200n8 serial'"\


#execute the commands in bash

subprocess.call(args, shell=False)

新错误

./createvmattend.1.py 
usage: virt-install --name NAME --memory MB STORAGE INSTALL [options]
virt-install: error: unrecognized arguments: --name bob --vcpus 1 --memory 2048 --cdrom /var/lib/libvirt/images/Centos.iso --disk-size 80 --os-variant centos7.0 --os-type linux --network bridge virbr0

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com