【问题标题】:AttributeError: 'tuple' object has no attribute 'get' while using POST request in PostmanAttributeError:在 Postman 中使用 POST 请求时,“tuple”对象没有属性“get”
【发布时间】:2022-01-04 05:06:07
【问题描述】:

我正在尝试使用 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 

The snapshot of the Postman POST request

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

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

【问题讨论】:

    标签: javascript python flask postman


    【解决方案1】:

    我假设你正在学习 udemy 区块链课程,结果证明这只是邮递员的问题,看看这个 Flask app request.get_json() return (Ellipsis, Ellipsis) instead of json

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-07
        • 2019-05-23
        • 1970-01-01
        • 2020-04-21
        • 1970-01-01
        • 1970-01-01
        • 2021-03-18
        • 2023-01-26
        相关资源
        最近更新 更多