相关文章推荐
怕老婆的口罩  ·  react ...·  1 年前    · 
果断的风衣  ·  jQuery ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams @app.route("/predictsentiment/<query>",method=['GET']) def predict(query): sentiment = sentimentanalyzer.returnSentiment(query) return flask.jsonify(sentiment) if __name__ == "__main__": app.run()

You need to import Flask class from flask module.

from flask import Flask
import sentimentanalyzer
app = Flask(__name__)
@app.route("/")
def default() :
    return "Hello world>>!!"
@app.route("/predictsentiment/<query>",methods=['GET'])
def predict(query):
    sentiment = sentimentanalyzer.returnSentiment(query)
    return flask.jsonify(sentiment)
if __name__ == '__main__':
    app.run()
                on line @app.route("/predictsentiment/<query>",methods=['GET']) you wrote method instead methods, pay also attention to /predictsentiment/<query> and def predict(qurey): (qurey)
– Matteo Pasini
                Jun 16, 2021 at 15:21
                after all corrections i got this Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)
– umesh hb
                Jun 16, 2021 at 15:27
                The http get call on route "/" returns 200 and print "Hello Wolrd"? If so, the error is inside the method sentimentanalyzer.returnSentiment(query), I suggest you open another question as this is about the flask error.
– Matteo Pasini
                Jun 16, 2021 at 15:28
@app.route("/predictsentiment/<query>",methods=['GET'])
def predict(query):
    sentiment = sentimentanalyzer.returnSentiment(query)
    return flask.jsonify(sentiment)
if __name__ == '__main__':
    app.run()

Though the above code is correct, your error may be the initialization or the structure of the app. Please post the structure. init.py needs to be put in a directory and the directory is called. Try renaming your init.py to app.py, should solve the error.

As a reference the Quickstart docs here: https://flask.palletsprojects.com/en/1.1.x/quickstart/

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
    return 'Hello, World!'

You need to create an object from the Flask class to get started.

And methods needs to be plural. (ref: https://flask.palletsprojects.com/en/1.1.x/quickstart/#http-methods)

Not relevant tot the question the default route has invalid syntax with the double backticks resulting in:

  File "/home/tom/tmp/test.py", line 8
    return "Hello world>>!!"``
SyntaxError: invalid syntax

Regards,

You need to import the flask class from the flask module. Check how to make minimal application here

import flask 
import sentimentanalyzer
app: flask.Flask = flask.Flask(__name__)
@app.route("/")
def default() :
    return "Hello world>>!!"
@app.route("/predictsentiment/<query>")
def predict(query):
    sentiment = sentimentanalyzer.returnSentiment(query)
    return flask.jsonify(sentiment)
if _name_== "  main  ":
    app.run()
                Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)
– umesh hb
                Jun 16, 2021 at 15:27
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.