发布到在heroku上部署的应用程序时,请求为空

时间:2019-05-11 16:06:03

标签: python heroku

我正在尝试过帐到已部署在heroku上的服务器,但是服务器上的“ request”变量似乎为空,因为我尝试使用request.get_json()导致崩溃。

我尝试通过使用pytest测试服务器功能来在本地测试服务器,并且这样做时,它可以完美运行。没有错误或警告。仅当部署到heroku时才会发生。我要发布到服务器的测试有效载荷是'{“ firstname”:“ pelle”,“ lastname”:“ Johansson”,“ phonenumber”:0323256327,“ email”:“ test@gmail.com”,“密码”:“ abbe123”}'

用于处理发布请求的服务器代码(server.py)

@app.route('/user', methods=["POST"])
def new_user():
    # Checking if request is available
    try:
        in_data = request.get_json()
    except:
        return jsonify({'msg': 'Could not get a request'}), 422

    # Checking the parameters so they contain the right data
    try:
        in_data = request.get_json()
        foo = in_data['firstname']
        foo = in_data['lastname']
        foo = in_data['phonenumber']
        foo = in_data['email']
        foo = in_data['password']
    except:
        return jsonify({'msg': 'One or more fields are missing values'}), 422

主要功能也与上述(server.py)位于同一文件中

if __name__ == '__main__':
    app.debug=True
    port1 = int(os.environ.get('PORT', 33507))
    app.run(port=port1)

我想要得到的是200代码返回,并附加了json。问题是,当服务器部署在heroku上并且我尝试过POST时,请求变量为空。

0 个答案:

没有答案