Betafish
Betafish

Reputation: 1262

Python (Flask + Swagger) Flasgger throwing 404 error

I am trying to use swagger ui as a frontend to query my flask application. I'm using Flasgger I tried a toy example as shown below

from flasgger import Swagger
from flask import Flask, logging

app = Flask(__name__)
Swagger(app)


# ENDPOINT = 1
@app.route('/hello',methods=['GET'])
def helloapp():
    return 'Hello World'

if __name__ == '__main__':
    app.run(debug=True,threaded=True,port=7005)
    file_handler = logging.FileHandler('app.log')
    app.logger.addHandler(file_handler)
    app.logger.setLevel(logging.INFO)

When i try to query the endpoint http://localhost:7005/hello. I get the result with 'Hello World'.

If I try to query http://localhost:7005/apidocs/ This shows me the base UI enter image description here


But, when I try to query the endpoint root. The swagger UI does not show up. It throws me a 404 Error

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Any pointers as to what is the issue ?.

Upvotes: 4

Views: 2867

Answers (1)

Kakashi
Kakashi

Reputation: 309

Try to add the endpoint root to your routes like this:

@app.route('/')

@app.route('/hello',methods=['GET'])
# ... 

Because you didn't define it as a route, it cannot be found on the server. I hope that this will help you

Upvotes: 1

Related Questions