[Python] fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that...

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    getting this error while executing the fast API code fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'main.SoluteSolvent'> is a valid pydantic field type

    class SoluteSolvent():
    solvent: Text
    solute: Text

    response = {}
    @app.get('/predict')
    def predict(sol:SoluteSolvent):
    data = sol.dict()
    solute = data['solute']
    solvent = data['solvent']
    results = predictions(solute, solvent)
    print(results)
    response["predictions"] = results[0].item()
    response["interaction_map"] = (results[1].detach().numpy()).tolist()
    return {'result':response}


    I was actually trying to replicate the code I have written for prediction in flask in fast API.

    response = {}
    @app.route('/predict', methods=["POST", "GET"])
    def predict():
    if request.method=='POST':
    solute = request.form["solute"]
    solvent = request.form["solvent"]

    else:
    solute = request.args.get("solute")
    solvent = request.args.get("solvent")

    results = predictions(solute, solvent)

    response["predictions"] = results[0].item()
    response["interaction_map"] = (results[1].detach().numpy()).tolist()
    return flask.jsonify({'result': response})

    Continue reading...

Compartilhe esta Página