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
评论列表
文章目录