Skip to content

Commit

Permalink
Don't use brotli if import fails
Browse files Browse the repository at this point in the history
  • Loading branch information
user234683 committed Aug 12, 2020
1 parent cc123d6 commit bd255a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions youtube/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd255a9

Please sign in to comment.