Replace np links with www to fix 403 forbidden error.
This commit is contained in:
@@ -26,7 +26,6 @@ _logger = logging.getLogger(__name__)
|
||||
# ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf.
|
||||
# http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails
|
||||
|
||||
|
||||
def main():
|
||||
"Main entry point"
|
||||
|
||||
@@ -60,6 +59,14 @@ def main():
|
||||
config.delete_refresh_token()
|
||||
|
||||
if config['log']:
|
||||
# Log request headers to the file (print hack only works on python 3.x)
|
||||
# from http import client
|
||||
# _http_logger = logging.getLogger('http.client')
|
||||
# client.HTTPConnection.debuglevel = 2
|
||||
# def print_to_file(*args, **_):
|
||||
# if args[0] != "header:":
|
||||
# _http_logger.info(' '.join(args))
|
||||
# client.print = print_to_file
|
||||
logging.basicConfig(level=logging.DEBUG, filename=config['log'])
|
||||
else:
|
||||
# Add an empty handler so the logger doesn't complain
|
||||
|
||||
@@ -251,7 +251,10 @@ class SubmissionContent(Content):
|
||||
def from_url(cls, reddit, url, loader, indent_size=2, max_indent_level=8,
|
||||
order=None):
|
||||
|
||||
url = url.replace('http:', 'https:')
|
||||
url = url.replace('http:', 'https:') # Reddit forces SSL
|
||||
# Sometimes reddit will return a 403 FORBIDDEN when trying to access an
|
||||
# np link while using OAUTH. Cause is unknown.
|
||||
url = url.replace('https://np.', 'https://www.')
|
||||
submission = reddit.get_submission(url, comment_sort=order)
|
||||
return cls(submission, loader, indent_size, max_indent_level, order)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -143,7 +143,7 @@ def test_content_submission_load_more_comments(reddit, terminal):
|
||||
assert content.get(390)['type'] == 'Comment'
|
||||
|
||||
|
||||
def test_content_submission_from_url(reddit, terminal):
|
||||
def test_content_submission_from_url(reddit, oauth, refresh_token, terminal):
|
||||
|
||||
url = 'https://www.reddit.com/r/AskReddit/comments/2np694/'
|
||||
SubmissionContent.from_url(reddit, url, terminal.loader)
|
||||
@@ -159,6 +159,14 @@ def test_content_submission_from_url(reddit, terminal):
|
||||
SubmissionContent.from_url(reddit, url[:-2], terminal.loader)
|
||||
assert isinstance(terminal.loader.exception, praw.errors.NotFound)
|
||||
|
||||
# np.* urls should not raise a 403 error when logged into oauth
|
||||
oauth.config.refresh_token = refresh_token
|
||||
oauth.authorize()
|
||||
url = 'https://np.reddit.com//r/LifeProTips/comments/441hsf//czmp112.json'
|
||||
with terminal.loader():
|
||||
SubmissionContent.from_url(reddit, url, terminal.loader)
|
||||
assert not terminal.loader.exception
|
||||
|
||||
|
||||
def test_content_subreddit_initialize(reddit, terminal):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user