使用tornado和TwitterMixin丢失OAuth请求令牌cookie错误
我正在使用龙卷风和 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发生这种情况的原因有两个:
oauth_token
参数,但未设置 cookie。不确定为什么会发生这种情况,您必须记录一些日志记录才能了解原因。无论如何,这不是一个“错误”,而是用户未经身份验证的标志。也许如果您发现您应该将他们重定向到授权 URL,然后让他们重试。
Two reasons why this might happen:
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.
我找到了解决方案!
这是由于我的 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.
我发生这种情况的原因是回调 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