python - 不是“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 作为父节点?
解决方案
推荐阅读
- javascript - (a: ?string) 和 (a?: string) 在流类型中有什么区别?
- laravel - 无法在 Laravel 中包含 Font Awesome
- mysql - 特定条件下Mysql中的计算
- javascript - 如何将多行输入通过管道传输到 Node.js 程序?
- android - 以编程方式获取通话期间的通话时间?
- python - python代码上的无效参数错误
- java - 在 StackPane 中的 AreaChart 上覆盖节点
- node.js - nodejs - 如何在 mongo 的最后一些文档中搜索
- homebrew - 尝试 brew install watchman 时地窖中未链接的小桶
- azure-data-factory - Azure 数据工厂:从 Salesforce 到 REST API