Reputation: 41
I've used Flask in a couple of projects, but never used the flask-restful package when creating restul APIs - so I thought I should give it a try.
However, I've come across a weird error that I can't understand - and the API doesn't work at all. The error message says
{
"message": "Not Found. You have requested this URI [/api/v1.0/items] but did you mean /api/v1.0/items ?",
"status": 404
}
run.py
from my_project import app
if __name__ == '__main__':
app.run(host=0.0.0.0, debug=app.config['DEBUG'])
my_project/_ init _.py
from flask import Flask
app = Flask(__name__)
from my_project.base import blueprint as BaseBluePrint
from my_project.api import blueprint as ApiBluePrint
app.register_blueprint(BaseBluePrint)
app.register_blueprint(ApiBluePrint, url_prefix='/api/v1.0')
my_project/api/_ init _.py
from flask import Blueprint
from flask.ext import restful
blueprint = Blueprint('api', __name__)
api = restful.Api(blueprint)
class ItemList(restful.Resource):
def get(self):
return false
api.add_resource(ItemList, '/items', endpoint='items')
What can cause this? Whatever I do, the error remains. Looking at the url_map
from Flask, I can see my route in there - and it looks fine. When moving away from blueprints and keeping it all in one file, it works. Python v2.7 and flask-restful v0.2.12 (installed from pip on Ubuntu Precise).
Upvotes: 4
Views: 2053
Reputation: 56
This worked for me:
Add ERROR_404_HELP=False in your environment:
app.config['ERROR_404_HELP'] = False
Upvotes: 3
Reputation: 340
I had similar problems related to trailing slashes, e.g. i defined api.com/endpoint and was sending request to api.com/endpoint/ and was having 404 errors.
Solution was to configure Flask application not to be strict about trailing slashes by: app.url_map.strict_slashes = False
Upvotes: -1