> It means that you already wrote content such as self.write or
> self.render when an exception occurred. Tornado catches the exception
> and tries to send a 50x status code, but the header has already been
> written.
Elias, thank you for answer. This is what I want to do. Explain my
thoughts more clearly, maybe somebody can give me any advices. In
BaseHandler class, function get_current_user I try to redirect user:
def get_current_user(self):
user_id = self.get_secure_cookie("user")
user_cookie = self.get_cookie("lp_login")
if user_id:
self.set_secure_cookie("user", user_id)
elif user_cookie:
# Redirect to needed url with logical
self.redirect("/auth/clogin?next=%s&u=%s&h=%s" %
(self.request.path, username, hashed_password))
When I open url, like '/' and in cookie have cookie 'lp_login' I get
this error.
> On Tue, May 25, 2010 at 9:17 AM, Grigory Fateyev <gfb...@gmail.com>
> wrote:
> > Hello!
> >
> > In my project I get such error:
> >
> > Traceback (most recent call last):
> > File "/home/greg/www/liveblogging/liveblog/tornado/web.py",
> > line 734, in _execute getattr(self,
> > self.request.method.lower())(*args, **kwargs) File
> > "/home/greg/www/liveblogging/liveblog/handlers/blog.py", line 374,
> > in get self.render("home.html", entries=entries, archives=archives,
> > **self.context) File
> > "/home/greg/www/liveblogging/liveblog/tornado/web.py", line 407, in
> > render self.finish(html) File
> > "/home/greg/www/liveblogging/liveblog/tornado/web.py", line 472, in
> > finish assert not self._finished AssertionError [E 100525 07:27:22
> > web:508] Cannot send error response after headers written
> >
> > What does it mean?
> >
> > --
> > Всего наилучшего!
> >
>
--
Всего наилучшего!
-Ben
> It's probably better if get_current_user doesn't send the redirect
> itself - both because of the problem you're seeing now and the fact
> that if you don't access current_user until after you start sending
> output the redirect may not work. Instead, get_current_user should
> return None if the user is not logged in, and you can use the
> decorator tornado.web.authenticated to redirect to the login page if
> needed.
Ben, I agreed with you, if the project has the only one method to
authorize users, I will use it, but in second authorize method I should
call external Auth API to get user's data. My problem is that I can't
find the right way how to do this. :( I tried use asynchronous request
to external API directly in BaseHandler's method get_current_user and
now trying redirect to CookieAuthHandler with all of logic but I am
stuck on this error. Such a petty. :(
--
Всего наилучшего!