Forums

Anyone Else Having Issues with Post Request using Flask on here?

The code is straight forward. The request reaches the endpoint, but for some reason a call to flask.request.json/json()/get_json() makes the flow go to the exception state. Why is this happening? I’ve checked on the client slide to make sure the data is proper in the json and that the call is make correctly.

Here’s the code to the flask post request endpoint:

@app.route('/get-ai-resp', methods=["POST"])
def get_ai_resp():
    try:
        data = request.json
        #print(data)
        return jsonify({"name": "Nateeeee"})
    except Exception as e:
        print(f"function error our.\n{e}")
        return jsonify({"error": "issueeee"})

Am I trippn and not seeing something or is there something else going on?

What can you see in your error logs?

.

Error running WSGI application
2023-11-28 06:25:58,676: ModuleNotFoundError: No module named 'openai'
2023-11-28 06:25:58,676:   File "/var/www/buzzy2427_pythonanywhere_com_wsgi.py", line 16, in <module>
2023-11-28 06:25:58,676:     from flask_app import app as application  # noqa
2023-11-28 06:25:58,676: 
2023-11-28 06:25:58,677:   File "/home/Buzzy2427/ai/flask_app.py", line 8, in <module>
2023-11-28 06:25:58,677:     from openai import OpenAI

I have installed this package numerous times and the system tells me it is there.

Make sure you installed it for the same Python version that you use to run your web app, and you reloaded the web app afterwards.