Catch HTTP errors (504, 500, whatever) when doing r.login()

pull/7/merge
David Trail 11 years ago
parent d8ee3aab26
commit da0f23e216

@ -1,12 +1,10 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
import praw import praw, argparse, ConfigParser
from praw.objects import Comment, Submission from praw.objects import Comment, Submission
import ConfigParser
import argparse
from datetime import datetime, timedelta from datetime import datetime, timedelta
from re import sub from re import sub
from time import sleep
try: try:
from loremipsum import get_sentence from loremipsum import get_sentence
except: except:
@ -38,7 +36,13 @@ _pass = config.get('main', 'password')
r = praw.Reddit(user_agent="Shreddit-PRAW 2.1") r = praw.Reddit(user_agent="Shreddit-PRAW 2.1")
if _user and _pass: if _user and _pass:
try:
r.login(_user, _pass)
except HTTPError:
# Try again (often get 500 errors)
sleep(10)
r.login(_user, _pass) r.login(_user, _pass)
else: else:
r.login() r.login()

Loading…
Cancel
Save