linux - python json unhashable type 'list' -


i have code submits json data server, gives error "unhashable type list"

hcatalog_nodes =["idh30-1.srv.acent.net.uk","idh30-2.srv.acent.net.uk","idh30-3.srv.acent.net.uk"] node in hcatalog_nodes:     data = json.dumps({[                             {                                 "rolename": "hcatalog",                                 "hostname": node                             }                          ]})     request = urllib2.request("https://192.168.0.76:9443/restapi/acent/api/v2/cluster/"+cluster_name+"/services/hbase/roles")     base64string = base64.encodestring('%s:%s' % ("admin", "admin")).replace('\n', '')     request.add_header("authorization", "basic %s" % base64string)     print "setting hbase roles on node %s " % (node)     result = urllib2.urlopen(request,data)     print result.read() 

error:

traceback (most recent call last):   file "/home/kshk/pycharmprojects/intelidh/autoidh.py", line 287, in <module>     main()   file "/home/kshk/pycharmprojects/intelidh/autoidh.py", line 278, in main     add_hcatalogroles()   file "/home/kshk/pycharmprojects/intelidh/autoidh.py", line 147, in add_hcatalogroles     "hostname": node typeerror: unhashable type: 'list'  process finished exit code 1 

any ideas how can set value of "node" in json request?

the problem on json.dumps() line:

data = json.dumps({[{"rolename": "hcatalog", "hostname": node}]}) 

this tries create set 1 list element. python list cannot element of set.


you wanted create dictionary instead , pass json.dumps():

data = json.dumps({"rolename": "hcatalog", "hostname": node}) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -