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?
--
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.
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.