python - python TypeError:ndarray类型的对象不是JSON可序列化的
问题描述
@app.route('/nodes/resolve', methods=['GET'])
def consensus():
replaced = blockchain.resolve_conflicts()
if replaced:
response = {
'message': 'Our chain was replaced',
'new_chain': blockchain.chain
}
else:
response = {
'message': 'Our chain is authoritative',
'chain': blockchain.chain
}
return jsonify(response), 200
解决冲突函数:
def resolve_conflicts(self):
neighbours = self.nodes
new_chain = None
max_length = len(self.chain)
for node in neighbours:
response = requests.get(f'http://{node}/chain')
if response.status_code == 200:
length = response.json()['length']
chain = response.json()['chain']
if length > max_length and self.valid_chain(chain):
max_length = length
new_chain = chain
if new_chain:
self.chain = new_chain
return True
return False
当我在 cmd 中运行“curl http://localhost:5000/nodes/resolve”时,它会抛出以下错误:
TypeError:ndarray 类型的对象不是 JSON 可序列化的
解决方案
推荐阅读
- java - 在 java 中准备语句时使用 long 而不是 int 有什么缺点吗?
- windows - CMake:英特尔编译器特定选项
- google-cloud-platform - 启动训练作业时出现 Google Cloud Machine Learning Engine 问题
- java - java和python并行处理的区别
- php - Laravel 在本地主机上不好用
- java - 如何使用 Prometheus 的 JMX exporter java 代理来收集自定义指标
- c# - C# 中数字的 xml 序列化使用什么格式?
- dialogflow-es - 如何使用 DialogFlow 开发的聊天机器人向用户发送欢迎消息
- php - PHP根据时间复制图片
- android - 为什么 RecyclerView onClick 方法不起作用?