4

I am having problems defining my own error custom messages. I am not exactly sure if I am doing it correctly but I am trying to follow the documentation:

http://flask-restful.readthedocs.org/en/latest/extending.html#define-custom-error-messages

This is what my code looks like:

from flask import Flask
from flask.ext import restful
myerrors = {
    'CannotFind':{
        'message':'We could not find it!',
        'status':404
    }
}
app = Flask(__name__)
api = restful.Api(app, errors = myerrors)

However when, I run this program i get an error:

TypeError: __init__() got an unexpected keyword argument 'errors'

The docs says Once your errors dictionary is defined, simply pass it to the Api constructor thats what I did no?

I also noticed in the documentation they used:

api = flask_restful.Api(app, errors=errors)

so I thought I was using something incorrectly and therefore I tried to import that flask_restful but it doesn't exists...

So now I am confused, please help!

1 Answer 1

8

The version of flask-restful you get when you install with pip will be v0.2.12

This version does not have the errors keyword argument for flask_restful.API.__init__ (github link)

To get the errors keyword you will need to install more recent code from github. There is instructions for how to do this on the flask-restful installation page.

Edit: As of 2014-11-23 this answer no longer applies because v0.3.0 of flask-restful was released and is on pypi.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, did they mention this in the doc? I couldn't find it.
I couldn't see any such info in the docs, no. I came to this conclusion from poking around the code and git repository.
Ah thats no good if they didn't write that anywhere :( Not happy about this. But thanks again.
I'm going to look into the Flask method described here: flask.pocoo.org/docs/0.10/patterns/apierrors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.