0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-26 02:55:17 +00:00

[extractor] Fix _create_request when headers is None

Closes #4164
This commit is contained in:
pukkandan 2022-06-25 19:41:22 +05:30
parent 74900105be
commit c043c24625
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
2 changed files with 7 additions and 7 deletions

View file

@ -730,14 +730,14 @@ def __can_accept_status_code(err, expected_status):
else: else:
return err.code in variadic(expected_status) return err.code in variadic(expected_status)
def _create_request(self, url_or_request, data=None, headers={}, query={}): def _create_request(self, url_or_request, data=None, headers=None, query=None):
if isinstance(url_or_request, urllib.request.Request): if isinstance(url_or_request, urllib.request.Request):
return update_Request(url_or_request, data=data, headers=headers, query=query) return update_Request(url_or_request, data=data, headers=headers, query=query)
if query: if query:
url_or_request = update_url_query(url_or_request, query) url_or_request = update_url_query(url_or_request, query)
return sanitized_Request(url_or_request, data, headers) return sanitized_Request(url_or_request, data, headers or {})
def _request_webpage(self, url_or_request, video_id, note=None, errnote=None, fatal=True, data=None, headers={}, query={}, expected_status=None): def _request_webpage(self, url_or_request, video_id, note=None, errnote=None, fatal=True, data=None, headers=None, query=None, expected_status=None):
""" """
Return the response handle. Return the response handle.
@ -765,8 +765,8 @@ def _request_webpage(self, url_or_request, video_id, note=None, errnote=None, fa
# geo unrestricted country. We will do so once we encounter any # geo unrestricted country. We will do so once we encounter any
# geo restriction error. # geo restriction error.
if self._x_forwarded_for_ip: if self._x_forwarded_for_ip:
if 'X-Forwarded-For' not in headers: headers = (headers or {}).copy()
headers['X-Forwarded-For'] = self._x_forwarded_for_ip headers.setdefault('X-Forwarded-For', self._x_forwarded_for_ip)
try: try:
return self._downloader.urlopen(self._create_request(url_or_request, data, headers, query)) return self._downloader.urlopen(self._create_request(url_or_request, data, headers, query))

View file

@ -3015,9 +3015,9 @@ def update_url_query(url, query):
query=urllib.parse.urlencode(qs, True))) query=urllib.parse.urlencode(qs, True)))
def update_Request(req, url=None, data=None, headers={}, query={}): def update_Request(req, url=None, data=None, headers=None, query=None):
req_headers = req.headers.copy() req_headers = req.headers.copy()
req_headers.update(headers) req_headers.update(headers or {})
req_data = data or req.data req_data = data or req.data
req_url = update_url_query(url or req.get_full_url(), query) req_url = update_url_query(url or req.get_full_url(), query)
req_get_method = req.get_method() req_get_method = req.get_method()