praww.py 文件源码

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

项目:hearthscan-bot 作者: d-schmidt 项目源码 文件源码
def __connect(self):

        connectTry = 1

        while True:
            try:
                log.debug("connect() creating reddit adapter")
                self.r = praw.Reddit(self.iniSite)

                # connect and check if instance has required scopes
                for scope in self.scopes:
                    if scope not in self.r.auth.scopes():
                        raise Exception('reddit init missing scope', scope)

                self.me = self.r.user.me()
                log.debug('connect() logged into reddit as: %s', self.me)
                return

            except prawcore.exceptions.RequestException as e:
                log.exception('connect() failed to send request')

            if connectTry >= self.connectAttempts:
                log.error('connect() connection attempt %s failed', connectTry)
                raise Exception('failed to connect')

            log.warn('connect() connection attempt %s failed', connectTry)
            # sleep up to 2^try sec before failing (3 trys = 6s)
            for s in range(2 ** connectTry):
                if self.killed:
                    raise Exception('killed')
                time.sleep(1)

            connectTry += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号