7

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.

1
  • 2
    Can you show the function registered as a handler for the route you're trying to access? Commented May 6, 2013 at 20:50

2 Answers 2

5

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.

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

1 Comment

The routes are built outside of a route decorator from a different config within the blueprint that gets built and registered with the the application factory I built...when making a second application I did the route method notation as strings without thinking.
1

This is, of course, one of these things that can have multiple different fixes (without seeing all of the original source code).

I got the same error in the HTML template that you did:

TypeError: 'str' object is not callable

My fix was to delete my (foolish) attempt to obtain the original request variables:

my_form = request.form

and just assign them by hand:

my_form.blah = request.form['blah']

Interestingly, the my_form = request.form executed without a problem, it only surfaced as an error in the HTML template.

Comments

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.