diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-01-31 20:06:15 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-01-31 20:06:15 -0800 |
commit | f787e4e2027583476ca34bd01c8462f6459369bb (patch) | |
tree | 3ac533d55d3f524a49abbd83957b9c87d65f357a /youtube/__init__.py | |
parent | cd4a2fb0ebb63600d9e66fa695c6517a968a78f8 (diff) | |
download | yt-local-f787e4e2027583476ca34bd01c8462f6459369bb.tar.lz yt-local-f787e4e2027583476ca34bd01c8462f6459369bb.tar.xz yt-local-f787e4e2027583476ca34bd01c8462f6459369bb.zip |
Give a proper error message for 429 errors
These occur when too many requests are coming from a Tor exit node.
Before, there would be an error page with an exception instructing users to report the issue.
But this is an expected and persistent issue.
Diffstat (limited to 'youtube/__init__.py')
-rw-r--r-- | youtube/__init__.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/youtube/__init__.py b/youtube/__init__.py index d8171c0..9e95256 100644 --- a/youtube/__init__.py +++ b/youtube/__init__.py @@ -1,6 +1,8 @@ +from youtube import util import flask import settings import traceback +from sys import exc_info yt_app = flask.Flask(__name__) yt_app.url_map.strict_slashes = False @@ -34,4 +36,14 @@ def commatize(num): @yt_app.errorhandler(500) def error_page(e): + if (exc_info()[0] == util.FetchError + and exc_info()[1].code == '429' + and settings.route_tor + ): + error_message = ('Error: Youtube blocked the request because the Tor' + ' exit node is overcrowded. Try getting a new exit node by' + ' restarting the Tor Browser.') + if exc_info()[1].ip: + error_message += ' Exit node IP address: ' + exc_info()[1].ip + return flask.render_template('error.html', error_message=error_message), 502 return flask.render_template('error.html', traceback=traceback.format_exc()), 500 |