From da0f23e2165a26d5c243cab82df8b1ee27bc591e Mon Sep 17 00:00:00 2001 From: David Trail Date: Sun, 28 Jul 2013 14:18:10 +0100 Subject: [PATCH] Catch HTTP errors (504, 500, whatever) when doing r.login() --- shreddit | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/shreddit b/shreddit index 283d8ef..7911c57 100755 --- a/shreddit +++ b/shreddit @@ -1,12 +1,10 @@ #!/usr/bin/env python2 -import praw +import praw, argparse, ConfigParser from praw.objects import Comment, Submission -import ConfigParser -import argparse from datetime import datetime, timedelta from re import sub - +from time import sleep try: from loremipsum import get_sentence except: @@ -38,7 +36,13 @@ _pass = config.get('main', 'password') r = praw.Reddit(user_agent="Shreddit-PRAW 2.1") if _user and _pass: - r.login(_user, _pass) + try: + r.login(_user, _pass) + except HTTPError: + # Try again (often get 500 errors) + sleep(10) + r.login(_user, _pass) + else: r.login()