From 74658f184bc9d7c6cc17ff092eb26a14ffe6213c Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 16 Feb 2019 14:26:03 -0800 Subject: fetch_url: Ensure urllib never leaks python version --- youtube/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'youtube') diff --git a/youtube/common.py b/youtube/common.py index df8280d..cb963ce 100644 --- a/youtube/common.py +++ b/youtube/common.py @@ -182,7 +182,12 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookieja ''' headers = dict(headers) # Note: Calling dict() on a dict will make a copy headers['Accept-Encoding'] = 'gzip, br' - + + # prevent python version being leaked by urllib if User-Agent isn't provided + # (urllib will use ex. Python-urllib/3.6 otherwise) + if 'User-Agent' not in headers and 'user-agent' not in headers and 'User-agent' not in headers: + headers['User-Agent'] = 'Python-urllib' + if data is not None: if isinstance(data, str): data = data.encode('ascii') -- cgit v1.2.3