flask-RESTful : why do I get an AssertionError when parsing an argument with the wrong type?
Question: I'm using flask-RESTful for the first time. In the [docs](http://flask-
restful.readthedocs.org/en/0.3.5/quickstart.html#argument-parsing) it says :

> Using the reqparse module also gives you sane error messages for free. If an
> argument fails to pass validation, Flask-RESTful will respond with a 400 Bad
> Request and a response highlighting the error.

However in my case, I get an exception AssertionError instead.

Here's the code:

    
    
    #! /usr/bin/python
    # -*- coding: UTF-8 -*-
    
    from flask import Flask
    from flask.ext.restful import Api, Resource, reqparse
    
    
    class Test(Resource):
        @staticmethod
        def put(id):
            parser = reqparse.RequestParser()
            parser.add_argument('arg1')
            parser.add_argument('arg2', type=int, help='helptext')
            args = parser.parse_args()
            return args, 200
    
    app = Flask(__name__)
    api = Api(app)
    
    api.add_resource(Test, '/v1.0/test/<int:id>', endpoint='test')
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5001, debug=True)
    

When I test this with right values, it works:

    
    
    $ curl -i  -H "Accept: application/json"  -X PUT --data "arg1=ABC&arg2=1"     http://192.0.0.7:5001/v1.0/test/1
    HTTP/1.0 200 OK
    Content-Type: application/json
    Content-Length: 38
    Server: Werkzeug/0.8.3 Python/2.6.6
    Date: Fri, 15 Apr 2016 11:59:48 GMT
    
    {
        "arg1": "ABC", 
        "arg2": 1
    }
    

However if I put a wrong value for arg2, instead of getting a status code 400
with an error message I get an exception:

    
    
    curl -i  -H "Accept: application/json"  -X PUT --data "arg1=ABC&arg2=A"     http://192.0.0.7:5001/v1.0/test/1
    HTTP/1.0 500 INTERNAL SERVER ERROR
    Content-Type: text/html; charset=utf-8
    Connection: close
    Server: Werkzeug/0.8.3 Python/2.6.6
    Date: Fri, 15 Apr 2016 12:04:25 GMT
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
    <html>
      <head>
        <title>AssertionError // Werkzeug Debugger</title>
        <link rel="stylesheet" href="?__debugger__=yes&amp;cmd=resource&amp;f=style.css" type="text/css">
        <script type="text/javascript" src="?__debugger__=yes&amp;cmd=resource&amp;f=jquery.js"></script>
        <script type="text/javascript" src="?__debugger__=yes&amp;cmd=resource&amp;f=debugger.js"></script>
        <script type="text/javascript">
          var TRACEBACK = 27516816,
              CONSOLE_MODE = false,
              EVALEX = true,
              SECRET = "uovVRKyVTy1b8gi5Yc3t";
        </script>
      </head>
      <body>
        <div class="debugger">
    <h1>AssertionError</h1>
    <div class="detail">
      <p class="errormsg">AssertionError</p>
    </div>
    <h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
    <div class="traceback">
    
      <ul><li><div class="frame" id="frame-27516688">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask/app.py"</cite>,
          line <em class="line">1701</em>,
          in <code class="function">__call__</code></h4>
      <pre>return self.wsgi_app(environ, start_response)</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215145552">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask/app.py"</cite>,
          line <em class="line">1689</em>,
          in <code class="function">wsgi_app</code></h4>
      <pre>response = self.make_response(self.handle_exception(e))</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215148944">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask_restful/__init__.py"</cite>,
          line <em class="line">271</em>,
          in <code class="function">error_router</code></h4>
      <pre>return original_handler(e)</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215149072">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask_restful/__init__.py"</cite>,
          line <em class="line">268</em>,
          in <code class="function">error_router</code></h4>
      <pre>return self.handle_error(e)</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215149136">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask/app.py"</cite>,
          line <em class="line">1687</em>,
          in <code class="function">wsgi_app</code></h4>
      <pre>response = self.full_dispatch_request()</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215149008">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask/app.py"</cite>,
          line <em class="line">1360</em>,
          in <code class="function">full_dispatch_request</code></h4>
      <pre>rv = self.handle_user_exception(e)</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215149200">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask_restful/__init__.py"</cite>,
          line <em class="line">271</em>,
          in <code class="function">error_router</code></h4>
      <pre>return original_handler(e)</pre>
    </div>
    
    <li><div class="frame" id="frame-139714215149264">
      <h4>File <cite class="filename">"/usr/lib/python2.6/site-packages/flask/app.py"</cite>,
          line <em class="line">1246</em>,
          in <code class="function">handle_user_exception</code></h4>
      <pre>assert exc_value is e</pre>
    </div>
    </ul>
      <blockquote>AssertionError</blockquote>
    </div>
    
    <div class="plain">
      <form action="http://paste.pocoo.org/" method="post">
        <p>
          <input type="hidden" name="language" value="pytb">
          This is the Copy/Paste friendly version of the traceback.  <span
          class="pastemessage">You can also paste this traceback into LodgeIt:
          <input type="submit" value="create paste"></span>
        </p>
        <textarea cols="50" rows="10" name="code" readonly>Traceback (most recent call last):
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1701, in __call__
        return self.wsgi_app(environ, start_response)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1689, in wsgi_app
        response = self.make_response(self.handle_exception(e))
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 271, in error_router
        return original_handler(e)
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 268, in error_router
        return self.handle_error(e)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1687, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1360, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 271, in error_router
        return original_handler(e)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1246, in handle_user_exception
        assert exc_value is e
    AssertionError</textarea>
      </form>
    </div>
    <div class="explanation">
      The debugger caught an exception in your WSGI application.  You can now
      look at the traceback which led to the error.  <span class="nojavascript">
      If you enable JavaScript you can also use additional features such as code
      execution (if the evalex feature is enabled), automatic pasting of the
      exceptions and much more.</span>
    </div>
          <div class="footer">
            Brought to you by <strong class="arthur">DON'T PANIC</strong>, your
            friendly Werkzeug powered traceback interpreter.
          </div>
        </div>
      </body>
    </html>
    
    <!--
    
    Traceback (most recent call last):
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1701, in __call__
        return self.wsgi_app(environ, start_response)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1689, in wsgi_app
        response = self.make_response(self.handle_exception(e))
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 271, in error_router
        return original_handler(e)
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 268, in error_router
        return self.handle_error(e)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1687, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1360, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/lib/python2.6/site-packages/flask_restful/__init__.py", line 271, in error_router
        return original_handler(e)
      File "/usr/lib/python2.6/site-packages/flask/app.py", line 1246, in handle_user_exception
        assert exc_value is e
    AssertionError
    
    -->
    

This is all running on a Centos 6.5 with

  * Python 2.6.6
  * Flask (0.9) 
  * Flask-RESTful (0.3.5)

EDIT: If I run the server with `debug=False`, I get:

    
    
    $ curl -i  -H "Accept: application/json"  -X PUT --data "arg1=ABC&arg2=A"     http://192.0.0.7:5001/v1.0/test/1 
    HTTP/1.0 500 INTERNAL SERVER ERROR
    Content-Type: application/json
    Content-Length: 37
    Server: Werkzeug/0.8.3 Python/2.6.6
    Date: Fri, 15 Apr 2016 12:50:37 GMT
    
    {"message": "Internal Server Error"}
    


Answer: Upgraded flask to 0.10.1 and the problem disappears.

