python - Rest framework: TypeError: 'exceptions.KeyError' object is not callable on invalid token -


i'm using rest framework's token authentication api. i've found issue that, if token provided in request invalid, instead of returning invalid token response, django throws typeerror @ /api/users/: 'exceptions.keyerror' object not callable.

i checked on trace, , found this: in django/db/models/query.py(django version=1.7) file line no 357, inside raise doesnotexists exception call, actual exception typeerror raised self.model._meta.object_name.

    if num == 1:         return clone._result_cache[0]     if not num:         raise self.model.doesnotexist(             "%s matching query not exist." %             self.model._meta.object_name) 

does knows why model's object_name became exception.keyerror rather token?

bizarrely, got when had line in code:

except keyerror, models.mymodel.doesnotexist: 

where comma interpreted "as", redefining models.mymodel.doesnotexist keyerror , causing "exception.keyerror not callable" when creating one.

what meant was:

except (keyerror, models.mymodel.doesnotexist): 

Comments