302 views
Skip to first unread message

Shane Spencer

unread,
May 23, 2013, 3:36:03 PM5/23/13
to python-...@googlegroups.com
I wish other people were running into these problems so that google would return the answers.

So I am using coroutines just like in the documentation for the TwitterMixIn.. infact it is direct copy/paste.

I get a response back from the Twitter OAUTH service, however self._headers_written) is set BEFORE self._on_request_token is called.. making the redirect at the end of it useless and it throws an exception of course.

I'm not entirely sure where to start diagnosing this problem... could this be because I am not yielding the authenticate_redirect/authorize_redirect or returning it directly?

spen...@gmail.com

unread,
May 23, 2013, 4:17:56 PM5/23/13
to python-...@googlegroups.com, sh...@bogomip.com
Apparently I failed to use a subject line.. my apologies.

Ben Darnell

unread,
May 23, 2013, 10:31:12 PM5/23/13
to Tornado Mailing List
On Thu, May 23, 2013 at 3:36 PM, Shane Spencer <sh...@bogomip.com> wrote:
I wish other people were running into these problems so that google would return the answers.

So I am using coroutines just like in the documentation for the TwitterMixIn.. infact it is direct copy/paste.

I get a response back from the Twitter OAUTH service, however self._headers_written) is set BEFORE self._on_request_token is called.. making the redirect at the end of it useless and it throws an exception of course.

This is often caused by a missing @asynchronous decorator, but if you've got that the next thing to look at is what exactly were the headers that were written?  Did something generate an error, or did the request finish "successfully"?
 

I'm not entirely sure where to start diagnosing this problem... could this be because I am not yielding the authenticate_redirect/authorize_redirect or returning it directly?

No, you don't need to yield or return the authorize_redirect call.

-Ben
 

--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Shane Spencer

unread,
May 23, 2013, 10:56:04 PM5/23/13
to python-...@googlegroups.com
Well now it's saying the request token is invalid (from Twitter) so as soon as I fix that.. I'll be able to test this.

In the mean time I moved over to OneAll for auth.. it blended right in to Tornado.  

Aleksey Silk

unread,
May 29, 2013, 8:49:51 AM5/29/13
to python-...@googlegroups.com
I use old way. Still don't understand how to use in new way! If you'll handle that, please inform me ...

С уважением, Алексей Силк
With best regards, Aleksey Silk
 
skype - rootiks
 


2013/5/29 m_ob...@onet.eu <m_ob...@onet.eu>
I think I've got the same problem in this code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import logging

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.gen
import tornado.auth

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class BaseHandler(tornado.web.RequestHandler):
    def get_current_user(self):
        return self.get_secure_cookie("user")

class MainHandler(BaseHandler, tornado.auth.TwitterMixin):
    @tornado.web.asynchronous
    @tornado.gen.coroutine
    def get(self):
        if self.get_argument("oauth_token", None):
            user = yield self.get_authenticated_user()
            if not user:
                raise tornado.web.HTTPError(500, "Twitter auth failed")
            self.set_secure_cookie("twitter_user", user)
            self.redirect("/")           
        else:
            self.authenticate_redirect()

class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/", MainHandler),
        ]
        settings = dict(
            twitter_consumer_key='RRLmRmSLfjMoJvi7qYfQ',
            twitter_consumer_secret='zgn6j0ln6eS6hvu9Ns9FELtD2uiRKwYfmXi3rfdYCfs',
            debug=True,
        )
        tornado.web.Application.__init__(self, handlers, **settings)

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = Application()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

It works after changing @tornado.gen.coroutine to @tornado.gen.engine.

Ben Darnell

unread,
May 29, 2013, 9:20:32 AM5/29/13
to Tornado Mailing List, sh...@bogomip.com
Ah, I see what's happening.  The auth*_redirect methods don't return Futures so they can't be yielded, but they should.  As a workaround for now you can continue to use @gen.engine and call these methods without yielding.

-Ben
Reply all
Reply to author
Forward
0 new messages