本文整理汇总了Python中katapult.requests.RequestHelper.set_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python RequestHelper.set_cookie方法的具体用法?Python RequestHelper.set_cookie怎么用?Python RequestHelper.set_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类katapult.requests.RequestHelper
的用法示例。
在下文中一共展示了RequestHelper.set_cookie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from katapult.requests import RequestHelper [as 别名]
# 或者: from katapult.requests.RequestHelper import set_cookie [as 别名]
def get(self):
helper = RequestHelper(self)
try:
if not users.is_current_user_admin():
helper.error(403, "admin required")
return
oauth_token = self.request.get("oauth_token")
if not oauth_token:
# initial request, I store the request token key/secret as cookies and redirect to twitter's auth page
request_token, auth_url = TwitterConnector.get_request_token_and_auth_url()
logging.debug("request token key:%s, secret:%s" % (request_token.key, request_token.secret))
helper.set_cookie("%s=%s; path=/" % (self._rtoken_key_cookie, request_token.key))
helper.set_cookie("%s=%s; path=/" % (self._rtoken_secret_cookie, request_token.secret))
helper.write_text("redirecting request token %s to %s" % (request_token.to_string(), auth_url))
self.redirect(auth_url)
else:
# post verification request
key = self.request.cookies.get(self._rtoken_key_cookie, None)
secret = self.request.cookies.get(self._rtoken_secret_cookie, None)
if not (key and secret):
helper.error(400, "key and secret not stored as cookies")
return
access_token = TwitterConnector.get_access_token(key, secret)
token_string = access_token.to_string()
ConfigurationAccessor.update(twitter_access_token=token_string)
helper.write_text("saved access token %s" % token_string)
except Exception, e:
msg = traceback.print_exc()
helper.error(500, msg)