TypeErrpr is raised when using `abort(404)`
<p>When I use <code>abort(status_code=404, detail='No such user', passthrough='json')</code>
This exception is raised:</p>

<p><code>TypeError: 'NoneType' object is not iterable</code>
This is the traceback:</p>

<pre><code>File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/appwrappers/identity.py", line 47, in __call__
    return self.next_handler(controller, environ, context)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/appwrappers/i18n.py", line 71, in __call__
    return self.next_handler(controller, environ, context)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/wsgiapp.py", line 285, in _dispatch
    return controller(environ, context)
File "/home/jugger/workspace/web/ave/ave/lib/base.py", line 27, in __call__
    return TGController.__call__(self, environ, context)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/controllers/dispatcher.py", line 119, in __call__
    response = self._perform_call(context)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/controllers/dispatcher.py", line 108, in _perform_call
    r = self._call(action, params, remainder=remainder, context=context)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/controllers/decoratedcontroller.py", line 125, in _call
    response = self._render_response(context, controller, output)
File "/home/jugger/.virtualenvs/ave/lib/python3.5/site-packages/tg/controllers/decoratedcontroller.py", line 220, in _render_response
    for name in exclude_names:
TypeError: 'NoneType' object is not iterable
--------------------- &gt;&gt; end captured logging &lt;&lt; ---------------------
</code></pre>

<p>This is my code:
I try to get an account that doesn't exist, so <code>NoResultFound</code> is caught and as the result <code>abort</code> must be done. but it raises the exception I mentioned above.</p>

<pre><code>@expose('json')
def get_one(self, account_id):
    """
    Get an account

    :param account_id :type: str

    :return Account :type: dict
    """
    try:
        _id = int(account_id)
    except ValueError:
        abort(status_code=400, detail='account_id must be int', passthrough='json')
    try:
        account = DBSession.query(Account).filter(Account.id == _id).one()
    except NoResultFound:
        abort(status_code=404, detail='No such user', passthrough='json')
    return dict(
        id=account.id,
        username=account.username,
        reputation=account.reputation,
        badges=account.badges,
        created=account.created,
        bio=account.bio
    )
</code></pre>

<p>That's something the authentication layer does, whenever is signaled back to the user that authentication is needed the challenger will intervene and force the user to login ( <a href="http://turbogears.readthedocs.io/en/latest/turbogears/authentication.html?highlight=challenger#how-it-works-in-turbogears" rel="nofollow">http://turbogears.readthedocs.io/en/latest/turbogears/authentication.html?highlight=challenger#how-it-works-in-turbogears</a> )</p>

<p>If you want to avoid that behaviour the easiest way is to use <code>tg.abort(401, passthrough=True)</code> which will skip such step, as you are talking about an API you probably want to use <code>passthrough='json'</code> which will provide a JSON response. See  <a href="http://turbogears.readthedocs.io/en/latest/reference/classes.html#tg.controllers.util.abort" rel="nofollow">http://turbogears.readthedocs.io/en/latest/reference/classes.html#tg.controllers.util.abort</a></p>

<p>Your response might then get caught by the <code>ErrorPageApplicationWrapper</code> depending on TurboGears version in such case make sure <code>ErrorController.document</code> has <code>@expose('json')</code> or you will face the crash you mentioned.</p>

python testing nose turbogears2