tgcloud tgcloud - 1 month ago 8x
JSON Question

Openstack output in json format

I am using novaclient to get the details from Openstack. i am able to retrieve the information, however i want to convert it into json format. i am using "to_dic()" but it;s throwing "Attribute" error on "server_details = server_id_name.to_dict()", not sure why.

AttributeError: "'tuple' object has no attribute 'to_dict'"

Code is given below,

from novaclient import client as novaclient
import json

nova = novaclient.Client(version='2.0',username='xxxx',api_key='xxxx',project_id='xxxx',auth_url='',insecure='True')

server_details = dict()
server = nova.servers.list()
for server in nova.servers.list():
server_id_name =,
server_details = server_id_name.to_dict()
for network in server.networks.items():
print network


It's a error in your python code. you should use

server_details[] =

to replace your code

server_id_name =,
server_details = server_id_name.to_dict()

BTW, you should learn more about python. If you want to change a tuple to a dict, you should see python-tuple-to-dict