简体   繁体   中英

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 在此处输入图片说明


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 ?.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM