-1

I'm working with flask, heroku and flutter but when I call the the url I got the following error. This is my code for the app.py:

from flask import Flask, jsonify, request
import pandas as pd
import numpy as np
import joblib
import traceback
from flask_restful import reqparse
app = Flask(__name__)

"""@app.route("/", methods=['GET'])
def hello():
    return "hey"""

@app.route('/', methods=['POST'])
def predict():
    lr = joblib.load("model.pkl")
    if lr:
        try:
            json = request.get_json()    
            model_columns = joblib.load("model_cols.pkl")
            temp=list(json[0].values())
            vals=np.array(temp)
            prediction = lr.predict(temp)
            print("here:",prediction)        
            return jsonify({'prediction': str(prediction[0])})

        except:        
            return jsonify({'trace': traceback.format_exc()})
    else:
        return ('No model here to use')
    


if __name__ == '__main__':
    app.run(debug=True)

It is already on the Heroku app. The link for the heroku is the following: https://myappflutterflask.herokuapp.com/

  • You are not allowing `GET` method in your home route so you can't directly go to the home page. – Aditya Dec 03 '20 at 05:39

1 Answers1

1

Looks like you're exposing the POST method in your program but accessing it using GET (perhaps via the web browser).

You may need to use a different client to test it: browser plugin, Postman, curl for example.