首页 > 解决方案 > 不是“NodeMixin”类型。-Python Anytree

问题描述

当我尝试使用 anytree 模块使用父节点的 json 值时,出现以下错误,如何获取 json 值作为父节点?

这是我的代码

def Get_Full_Name():
    name = names.get_full_name()
    return name


def Type_Name():
    ListType = ['Room', 'Building', 'Bed']
    number = random.sample([int(x) for x in range(1, 3)], 1)
    RandomList = ListType[number[0]]
    return RandomList



headers = {
    'accept': 'text/plain',
    'Content-Type': 'application/json-patch+json',
}

name = Get_Full_Name()
ListValue = Type_Name()
params = (
    ('name', name),
    ('type', 'BuildingGroup'),
)

data = '["{}"]'.format(name)

response = requests.post('http://SampleApiURL/', headers=headers,
                         params=params, data=data)


response_body = response.json()
print("Parent: " + response_body)
headers = {
    'accept': 'text/plain',
}

response2 = requests.get('http://SAmpleApiUrl/' + response_body, headers=headers)

response_body1 = response2.json()
RootNode = AnyNode(response_body1)
#ChildL2 = AnyNode(response_content="someValue", parent=RootNode)

exporter = JsonExporter(indent=4, sort_keys=True)
print  (exporter.export(RootNode))

我得到的错误是

Parent node {'locationId': 'LocationId', 'name': 'Andrew Rice', 'type': 'BuildingGroup', 'patientId': None, 'children': None} is not of type 'NodeMixin'.

如何使用 Json 作为父节点?

标签: pythonjsonanytree

解决方案


推荐阅读