繁体   English   中英

AttributeError: 'tuple' object 在 Postman 中使用 POST 请求时没有属性 'get'

[英]AttributeError: 'tuple' object has no attribute 'get' while using POST request in Postman

我正在尝试使用 request.get_json() 将来自 JSON 数据的节点添加到一个集合中。

@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 

Postman POST请求截图

我在 Spyder(Python 3.9)中遇到的错误:

line 178, in connect_node
nodes = json.get(nodes)
AttributeError: 'tuple' object has no attribute 'get' 

我假设您正在学习 udemy 区块链课程,结果证明这只是 postman 的问题,请查看Flask 应用程序 request.get_json() 返回(省略号,省略号)而不是 Z466DEEC76ECDF6324FCA6D38571

如果您正在使用 python 3.9 并收到此错误,请使用 python 3.6 在 anaconda 中构建一个虚拟环境,并将此 python 解释器用于所有 Spyder 控制台。 它适用于我的情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM