From d5f114a4d8fa80c384a53f2a9ea54d8eb82e0bb4 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 7 Aug 2016 21:56:19 -0700 Subject: [PATCH] Expand URLs. --- rtv/__main__.py | 9 ++++++++- rtv/objects.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rtv/__main__.py b/rtv/__main__.py index bb002df..e13acac 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -10,6 +10,7 @@ import warnings import six import praw import tornado +import requests from . import docs from .config import Config, copy_default_config, copy_default_mailcap @@ -132,7 +133,13 @@ def main(): # Open the supplied submission link before opening the subreddit if config['link']: - page.open_submission(url=config['link']) + # Expand shortened urls like https://redd.it/ + # Praw won't accept the shortened versions, add the reddit + # headers to avoid a 429 response from reddit.com + url = requests.head(config['link'], headers=reddit.http.headers, + allow_redirects=True).url + + page.open_submission(url=url) # Launch the subreddit page page.loop() diff --git a/rtv/objects.py b/rtv/objects.py index 75a3bb7..377751f 100644 --- a/rtv/objects.py +++ b/rtv/objects.py @@ -116,7 +116,7 @@ class LoadScreen(object): EXCEPTION_MESSAGES = [ (exceptions.RTVError, '{0}'), - (praw.errors.OAuthException, 'Not logged in'), + (praw.errors.OAuthException, 'OAuth Error'), (praw.errors.OAuthScopeRequired, 'Not logged in'), (praw.errors.LoginRequired, 'Not logged in'), (praw.errors.InvalidCaptcha, 'Error, captcha required'),