Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask : TypeError: 'str' object is not callable

Tags:

python

flask

I have a generated flask application that is giving me this traceback:

Traceback (most recent call last):
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/.virtualenvs/j/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
TypeError: 'str' object is not callable

but I cannot determine why or what is causing this at this point. The app starts and appears to run, but chokes on this traceback anytime I try to visit a route.

What is this and what would be causing this? I don't what object is a str and why it is not callable. This is the first I've seen something like this.

like image 202
blueblank Avatar asked May 06 '13 20:05

blueblank


1 Answers

That means that self.view_functions[rule.endpoint] is a string, not a function, thus cannot be called (with (...) operator). That said, it is difficult to tell what the issue without your code: Flask expects a function to be called and it gets a string. Did you use the @app.route decorator?

Try printing the value of self.view_functions[rule.endpoint] and see what comes out.

like image 159
Stefano Sanfilippo Avatar answered Oct 05 '22 06:10

Stefano Sanfilippo