'tuple' 对象没有属性 'rstrip'

'tuple' object has no attribute 'rstrip'

我遇到了这个问题:

'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 的问题吗?当我获取查询时

Cursor.fetchone returns 表示一行的序列(您的案例的元组)。

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

vmid = c.fetchone()[0]

或使用元组解包:

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