Opened 16 years ago

Closed 15 years ago

#7768 closed (duplicate)

r 'str' object is not callable in base.py

Reported by: William Martinez Pomares <wmartinez@…> Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

Working with SVN revision 7930, following the tutorial, up to the place where the votes view is created.
The line in the vote() method

   return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,)))

fails presenting a debug page that says:

TypeError at /polls/1/results/
'str' object is not callable
Request Method: 	GET
Request URL: 	http://127.0.0.1:8000/polls/1/results/
Exception Type: 	TypeError
Exception Value: 	'str' object is not callable
Exception Location: 	C:\Python25\lib\site-packages\django\core\handlers\base.py in get_response, line 85

I have found some relates issues (like 4700) that point to the INSTALLED_APPS settings and how the django.contrib.auth affects the get_response. I tried eliminating that application and still the error shows.
If using HttpResponseRedirect without the reverse (hardcoding the url) it fails too. If using render_to_response() instead, it works.

Another relate ticket may be 6442, but that one happens when the import error occurs. In this case the imports are ok in views.py, it is the HttpResponseRedirect that may have problems.

William Martinez.

Change History (12)

comment:1 by William Martinez Pomares <wmartinez@…>, 16 years ago

An update.

I found out a problem in the views.py, the actual results() method that is the one called when HttpResponseRedirect is executed (url is '/polls/3/results/'). It had a problem in the name, so it was not found. That may not cause an import issue like in ticket 6442 but it will probably raise an exception. I was about to set this ticket as a duplicaet of 6442, but it is slightly different in the cause. Still, it may be resolved around the same command line.

Here, as in 6442, the error should indicate the view was not found instead of the misleading TypeError at base.py.

William.

comment:2 by Adrian Holovaty, 16 years ago

Description: modified (diff)

(Fixed formatting in description)

comment:3 by Eric Holscher, 16 years ago

Resolution: worksforme
Status: newclosed

Ask on django-users, more than likely the tutorial is correct.

in reply to:  3 comment:4 by bengan, 16 years ago

Resolution: worksforme
Status: closedreopened

Replying to ericholscher:

Ask on django-users, more than likely the tutorial is correct.

But not for me. I have the same issue. Exactly the same.

comment:5 by James Bennett, 16 years ago

Resolution: worksforme
Status: reopenedclosed

The tutorial is correct; if you read the comments above you'll see that the original person who filed this ticket had an error of his own while following the tutorial, rather than an error due to the code in the tutorial. As Eric suggested, ask on django-users for further help rather than needlessly churning the ticket tracker.

comment:6 by William Martinez <wmartinez@…>, 16 years ago

Hello.
I'm the original person that wrote the ticket. It is NOT a tutorial problem I talked about, so this is not a django-users question.
Please read carefully:

In following the tutorial, I wrote something wrong, so it was supposed to fail.
I expected to see an error of method or view not found. Instead I saw another error, the one " 'str' object not callable' at base.py.
Following other bugs, it seems it actually raise an exception that is caught and ignored, leading to an error later on at base.py.
Bug 6442 explains this.

So, in summary:
-> If you have a typo in the view method, it will not tell you that. It will throw a misleading exception " 'str' object not callable' at base.py.
THAT, is the bug.

I won't reopen the ticket, if you fix bug 6442 it may get fixed.
Thanks.
William Martinez.

comment:7 by hannnndy <web@…>, 16 years ago

Resolution: worksforme
Status: closedreopened
Summary: HttpResponseRedirect causes a TypeError 'str' object is not callable in base.pyr 'str' object is not callable in base.py

why this error happens and how should i solve it

comment:8 by dc, 16 years ago

Resolution: worksforme
Status: reopenedclosed

Please ask on django-users for help.

comment:9 by Karen Tracey, 16 years ago

Replying to hannnndy <web@parsitech.com>:

why this error happens and how should i solve it

I don't know, because you have provided no information about what you are doing. The reported instances of this error are all user error, so tracking down what is going wrong is best done on django-users, where there are more people reading and likely to help, than in the ticket tracker. Or read through the comments here and in #6442 and see if you have made an error similar to others that led to this error message. The bug in Django here is that this error message is not very helpful in tracking down what your real error is, and that is covered by #6442.

comment:10 by ziofunk, 15 years ago

Resolution: worksforme
Status: closedreopened

comment:11 by ziofunk, 15 years ago

The same wrong error message is returned in a situation that is not described in #6442.
I have an urls.py inside my application. I have it correctly included in the project urls.py. When I use the first argument to the patterns() function to specify a prefix to be applied to each view function, if the prefix is mispelled I get the correct error saying that the module does not exist. When I don't put any prefix I get the wrong error message reported in this bug:

Exception Value: 'str' object is not callable
Exception Location: C:\Python25\lib\site-packages\django\core\handlers\base.py in get_response, line 85

comment:12 by Karen Tracey, 15 years ago

Resolution: duplicate
Status: reopenedclosed

While your exact reproduction scenario may differ from what is detailed in #6442, it sounds to me like the fix proposed for #6442 would cover this case as well. The fix suggested there is:

"I suggest that urlresolver would raise an exception on invalid look-ups."

If that fix were in place, then the resolve() call would raise an error instead of returning a string, and you'd never get to the point where subsequent code tried to call a string object.

So I'd say your scenario is just a different way of tripping over the same bug -- you just have a different way of injecting an invalid lookup into your urls.py. If you'd like to ensure your case is considered when #6442 is fixed, the right place to mention it is in #6442 itself, not here. We only need one open ticket to track improving this error situation.

Note: See TracTickets for help on using tickets.
Back to Top