diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-08-11 21:57:40 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-08-11 21:57:40 -0700 |
commit | bd255a9ab0734651a1129b470a9c51e6d63bd235 (patch) | |
tree | 6671dc194b41178e08c4af4ae2c908a9e32f3723 | |
parent | cc123d6761c50be40ab972550a257d40c2802856 (diff) | |
download | yt-local-bd255a9ab0734651a1129b470a9c51e6d63bd235.tar.lz yt-local-bd255a9ab0734651a1129b470a9c51e6d63bd235.tar.xz yt-local-bd255a9ab0734651a1129b470a9c51e6d63bd235.zip |
Don't use brotli if import fails
-rw-r--r-- | youtube/util.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/youtube/util.py b/youtube/util.py index ec25d40..b19f91b 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -2,7 +2,11 @@ import settings from youtube import yt_data_extract import socks, sockshandler import gzip -import brotli +try: + import brotli + have_brotli = True +except ImportError: + have_brotli = False import urllib.parse import re import time @@ -125,7 +129,10 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookieja and response cookies will be merged into it. ''' headers = dict(headers) # Note: Calling dict() on a dict will make a copy - headers['Accept-Encoding'] = 'gzip, br' + if have_brotli: + headers['Accept-Encoding'] = 'gzip, br' + else: + headers['Accept-Encoding'] = 'gzip' # prevent python version being leaked by urllib if User-Agent isn't provided # (urllib will use ex. Python-urllib/3.6 otherwise) |