api.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:rt_api 作者: NickMolloy 项目源码 文件源码
def _get_token(self):
        """Get an API token.

        Raises:
            AuthenticationError: if getting token fails.

        """
        client = BackendApplicationClient(client_id=CLIENT_ID)
        oauth = OAuth2Session(client=client)
        # Retry auth if error (to get around intermittent failures)
        latest_exception = None
        for i in range(3):
            try:
                token = oauth.fetch_token(
                    token_url=AUTH_URL, client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
                self.__token = token["access_token"]
                self.__session = oauth
                self._me = None
                return
            except (AccessDeniedError, InvalidClientError, MissingTokenError) as e:
                latest_exception = e
                continue
        raise AuthenticationError("Failed to get authentication token: {0}".format(latest_exception))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号