gpt4 book ai didi

python - “元组”对象没有属性 'rstrip'

转载 作者:行者123 更新时间:2023-11-30 23:12:10 24 4
gpt4 key购买 nike

我遇到了这个问题:

'tuple' object has no attribute 'rstrip'

我的脚本是:

def destroyVM(request,id):
conn = sqlite3.connect('testDB')
c = conn.cursor()
api = 'http://196.203.216.18:5555/client/api'
apikey = '3U7UPLR4JHYEzOhKe0JYnR_ICChdmuynnl0SdqmFzFgG4Hgd6BJHHjcSk2K3SsXUvheLEoN-SlRuEOpqZbqbVA'
secret = 'JU1gQk99VpAEZWWKxiR97w8mIPtSZsXwuORL6H2NKkve0EHDvBZ5IQN-CXHqMhVKmOLRcRhjyr4RPnTqAmD5Ig'
cloudstack = CloudStack.Client(api, apikey, secret) # ouvrir une connexion serveur/client
c.execute("SELECT vmid FROM vmm_vm where id ="+id+";");
conn.commit()
vmid = c.fetchone()
vm = cloudstack.destroyVirtualMachine({'id':vmid})

c.execute("DELETE FROM vmm_vm WHERE id = '"+id+"';")

conn.commit()

conn.close()

return render_to_response('vms.html',{'vms':Vm.objects.all()})

问题出在 vmid 上吗?当我获取查询时 enter image description here

最佳答案

Cursor.fetchone返回代表一行的序列(适合您的情况的元组)。

您需要从元组中提取项目。

vmid = c.fetchone()[0]

或使用元组解包:

vmid, = c.fetchone()  # same as (vmid,) = c.fetchone()

关于python - “元组”对象没有属性 'rstrip',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29932783/

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