python - 'tuple' object has no attribute 'rstrip' -
i got problem :
'tuple' object has no attribute 'rstrip'
my script :
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 vmm_vm id ="+id+";"); conn.commit() vmid = c.fetchone() vm = cloudstack.destroyvirtualmachine({'id':vmid}) c.execute("delete vmm_vm id = '"+id+"';") conn.commit() conn.close() return render_to_response('vms.html',{'vms':vm.objects.all()})
is problem in vmid ? when fetch query
cursor.fetchone
returns sequence (a tuple case) represent row.
you need extract item tuple.
vmid = c.fetchone()[0]
or using tuple unpacking:
vmid, = c.fetchone() # same (vmid,) = c.fetchone()
Comments
Post a Comment