使用tornado和TwitterMixin丢失OAuth请求令牌cookie错误

发布于 2024-11-25 16:29:58 字数 683 浏览 1 评论 0原文

我正在使用龙卷风和 TwitterMixin,并使用以下基本代码:

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() 

对我来说,它工作得很好,但有时,我的应用程序的用户会收到 500 错误,其中显示: 缺少 OAuth 请求令牌 cookie

我不知道它是来自浏览器还是来自 twitter api 回调配置。 我查看了龙卷风代码,但不明白为什么会出现此错误 出现。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何以心动 2024-12-02 16:29:58

发生这种情况的原因有两个:

  1. 某些用户可能关闭了 cookie,在这种情况下这将不起作用。
  2. 该 cookie 尚未经过身份验证。可能已设置了 oauth_token 参数,但未设置 cookie。不确定为什么会发生这种情况,您必须记录一些日志记录才能了解原因。

无论如何,这不是一个“错误”,而是用户未经身份验证的标志。也许如果您发现您应该将他们重定向到授权 URL,然后让他们重试。

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.

风尘浪孓 2024-12-02 16:29:58

我找到了解决方案!

这是由于我的 DNS 造成的。

我没有设置 www.mydomain.com 和 mydomain.com 的重定向,因此有时 cookie 会设置在 www.mydomain.com 中。有时不是,然后我的服务器没有检查好位置,没有找到 cookie,然后向我发送 500 错误。

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.

寂寞美少年 2024-12-02 16:29:58

我发生这种情况的原因是回调 URL 配置指向不同的域。

查看应用程序的设置选项卡:https://dev.twitter.com/apps/ 或者如果收到错误的用户正在从不同的域访问您的网站。

请参阅:http://groups.google.com/group/python-tornado /browse_thread/thread/55aa42eef42fa1ac

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文