Missing OAuth request token cookie error using tornado and TwitterMixin

你说的曾经没有我的故事 提交于 2019-12-12 10:25:23

问题


I'm using tornado and the TwitterMixin and I use the following basic code:

class OauthTwitterHandler(BaseHandler, tornado.auth.TwitterMixin): 
    @tornado.web.asynchronous 
    def get(self): 
        if self.get_argument("oauth_token", None): 
            self.get_authenticated_user(self.async_callback(self._on_auth)) 
            return 
        self.authorize_redirect() 
    def _on_auth(self, user): 
        if not user: 
            raise tornado.web.HTTPError(500, "Twitter auth failed") 
        self.write(user) 
        self.finish() 

For me it works very well but sometimes, users of my application get a 500 error which says: Missing OAuth request token cookie

I don't know if it comes from the browser or the twitter api callback configuration. I've looked through the tornado code and I don't understand why this error appears.


回答1:


Two reasons why this might happen:

  1. Some users may have cookies turned off, in which case this won't work.
  2. The cookie hasn't authenticated. It's possible that the oauth_token argument is set, but the cookie is not. Not sure why this would happen, you'd have to log some logging to understand why.

At any rate, this isn't an "error," but rather a sign the user isn't authenticated. Maybe if you see that you should just redirect them to the authorize URL and let them try again.




回答2:


I found the solution !!

It was due to my DNS.

I didn't put the redirection for www.mydomain.com and mydomain.com so sometimes the cookie was set in www. and sometimes not then my server didn't check in the good place, didn't find the cookie and then send me a 500 error.




回答3:


The reason this was happening to me is that the Callback URL configuration was pointing to a different domain.

Take a look at the settings tab for your application at https://dev.twitter.com/apps/ or if the users getting the error are accessing your site from a different domain.

See: http://groups.google.com/group/python-tornado/browse_thread/thread/55aa42eef42fa1ac



来源:https://stackoverflow.com/questions/6774563/missing-oauth-request-token-cookie-error-using-tornado-and-twittermixin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!