我有一段代码,它向服务器提交JSON数据,但是出现了“unhashable type list”错误。
hcatalog_nodes =["idh30-1.srv.acent.net.uk","idh30-2.srv.acent.net.uk","idh30-3.srv.acent.net.uk"]
for 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 up HBase roles on node %s " % (node)
result = urllib2.urlopen(request,data)
print result.read()
错误:
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 with exit code 1
你有什么想法可以在JSON请求中设置"node"的值吗?
{[...
- 这是一个集合,其中一个元素是列表。集合元素只能是可哈希类型。列表是不可哈希的,因此会出现错误。 - Lukas Graf