Django & twill - session cookies not being set
I'm testing a django application with twill, and django-test-utils, and it's not logging me in.
I think it's not setting the django session cookie. I go to a webpage (in twill) that calls request.session.set_test_cookie()
, and after that call returns, twill.show_cookies()
(which should print out the cookies开发者_StackOverflow中文版), shows no cookies. In another page/view, request.session.test_cookie_worked()
returns False
.
Oddly, another page, calls request.set_cookie(...)
to manually set a cookie, and that works. twill.show_cookies()
shows that cookie. So some cookies are working, but the session middleware just doesn't seem to be working...
What could be going on? How do I get the django session cookie to be set in twill?
Some other people have had similar problems, example on django-users, comment about cookies on another twill/django script
As F.C. said, if the client and server are different machines with non-matching times (or even possibly timezones), you may end up with cookie expiration problems.
I just double-checked the code for set_test_cookie()
, and it looks like it sets that value pretty normally. Are you certain that the page you are having trouble with isn't returning an error (and thus not setting the test_cookie
)? There are a whole bunch of ways that could happen, but off the top of my head:
- Twill may not send a
Host
header your app requires - Twill may not send a
referer
your app requires - Twill may not support compression/encryption/multipart/something else
- Twill may not perfectly emulate a browser in some other fashion
- One of your other middlewares may require some combination of the above
Double-check your other middlewares. Try making a blank project that ONLY tests this issue. A blank project with just the admin enabled should be enough. If you can replicate it in a minimal configuration, we can be more helpful with chasing down the bug.
精彩评论