Python 3.x 无法将Postman上的链接连接到Flask
我有3个几乎相同的代码模拟3个加密矿工,每个都在不同的端口5000、5001和5002上运行。唯一的区别是最后一行代码:Python 3.x 无法将Postman上的链接连接到Flask,python-3.x,flask,postman,Python 3.x,Flask,Postman,我有3个几乎相同的代码模拟3个加密矿工,每个都在不同的端口5000、5001和5002上运行。唯一的区别是最后一行代码: app.run(host="0.0.0.0", port=5001) 然后我通过邮递员把他们联系起来。但是,5001每次都无法连接到其他两个。另外两个很好用 错误消息如下所示: 这对我来说没有意义,因为python脚本和邮递员设置是对称的,每次5001都失败。重新启动Postman和python没有帮助。是因为邮递员有带宽问题吗?谢谢你的评论 这就是我连接节点的方式。它同
app.run(host="0.0.0.0", port=5001)
然后我通过邮递员把他们联系起来。但是,5001每次都无法连接到其他两个。另外两个很好用
错误消息如下所示:
这对我来说没有意义,因为python脚本和邮递员设置是对称的,每次5001都失败。重新启动Postman和python没有帮助。是因为邮递员有带宽问题吗?谢谢你的评论
这就是我连接节点的方式。它同样适用于其他两个脚本
@app.route('/connect_node', methods = ['POST'])
def connect_node():
json = request.get_json()
nodes = json.get('nodes')
if nodes is None:
return "No node", 400
for node in nodes:
blockchain.add_node(node)
response = {'message': 'All the nodes are now connected. The Mycoin Blockchain now contains the following nodes:',
'total_nodes': list(blockchain.nodes)}
return jsonify(response), 201
当我尝试调试模式时,以下是日志:
File "D:\Dropbox\3350\homework\mini blockchain and crypto currency\MyCoin
cryptocurrency\node2.py", line 161, in connect_node
nodes = json.get('nodes')
AttributeError: 'NoneType' object has no attribute 'get'
此处有更详细的调试日志:
在正文中设置
JSON
它还将
Content-Type
标题设置为application/json
您是否有5001
服务器的日志?尝试使用调试标志运行它。它成功绑定到该端口了吗?也许它被其他应用程序占用了。非常感谢@AdrianKrupa。我对邮递员很陌生。请问如何检查和释放此端口?我在Postman上找不到服务器的日志。请检查flask应用程序中的日志。用app.Run运行flask(host=“0.0.0.0”,port=5001,Debug=True)并检查输出。非常感谢。它追溯到python中的这一行:nodes=json.get('nodes'),并说AttributeError:'NoneType'对象没有属性'get'