Skip to content

Commit

Permalink
[extractor/common] Handle ssl.CertificateError in _request_webpage (c…
Browse files Browse the repository at this point in the history
…loses #26601)

ssl.CertificateError is raised on some python versions <= 3.7.x
  • Loading branch information
dstftw committed Sep 17, 2020
1 parent cdc55e6 commit f8c7bed
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion youtube_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import random
import re
import socket
import ssl
import sys
import time
import math
Expand Down Expand Up @@ -623,9 +624,12 @@ def _request_webpage(self, url_or_request, video_id, note=None, errnote=None, fa
url_or_request = update_url_query(url_or_request, query)
if data is not None or headers:
url_or_request = sanitized_Request(url_or_request, data, headers)
exceptions = [compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error]
if hasattr(ssl, 'CertificateError'):
exceptions.append(ssl.CertificateError)
try:
return self._downloader.urlopen(url_or_request)
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
except tuple(exceptions) as err:
if isinstance(err, compat_urllib_error.HTTPError):
if self.__can_accept_status_code(err, expected_status):
# Retain reference to error to prevent file object from
Expand Down

0 comments on commit f8c7bed

Please sign in to comment.