What does this error mean?

1,013 views
Skip to first unread message

Grigory Fateyev

unread,
May 25, 2010, 9:17:14 AM5/25/10
to Tornado server
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?

--
Всего наилучшего!

Elias Torres

unread,
May 25, 2010, 1:25:09 PM5/25/10
to python-...@googlegroups.com
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

Grigory Fateyev

unread,
May 26, 2010, 7:14:32 AM5/26/10
to python-...@googlegroups.com
Hello Elias Torres!

On Tue, 25 May 2010 13:25:09 -0400 you wrote:

> 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?
> >
> > --
> > Всего наилучшего!
> >
>


--
Всего наилучшего!

David P. Novakovic

unread,
May 26, 2010, 8:27:28 AM5/26/10
to python-...@googlegroups.com
You need to check self._finished in the get() method (or the callback
it returns to) and do nothing if it is True.

Ben Darnell

unread,
May 26, 2010, 1:35:43 PM5/26/10
to python-...@googlegroups.com
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

Grigory Fateyev

unread,
May 27, 2010, 8:53:45 AM5/27/10
to python-...@googlegroups.com
Hello Ben Darnell!

On Wed, 26 May 2010 10:35:43 -0700 you wrote:

> 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. :(


--
Всего наилучшего!

Reply all
Reply to author
Forward
0 new messages