pretrained-models.pytorch icon indicating copy to clipboard operation
pretrained-models.pytorch copied to clipboard

SSL certificate is expired

Open qaohv opened this issue 2 years ago • 2 comments

Hi! I'm trying to download pretrained densenet169 and getting error "certificate verify failed: certificate has expired".

import pretrainedmodels
pretrainedmodels.densenet169(num_classes=1000, pretrained='imagenet')
Downloading: "http://data.lip6.fr/cadene/pretrainedmodels/densenet169-f470b90a4.pth" to /root/.cache/torch/hub/checkpoints/densenet169-f470b90a4.pth
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/urllib/request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/opt/conda/lib/python3.8/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/conda/lib/python3.8/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/conda/lib/python3.8/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/conda/lib/python3.8/http/client.py", line 1007, in _send_output
    self.send(msg)
  File "/opt/conda/lib/python3.8/http/client.py", line 947, in send
    self.connect()
  File "/opt/conda/lib/python3.8/http/client.py", line 1421, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/opt/conda/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/opt/conda/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/opt/conda/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.8/site-packages/pretrainedmodels/models/torchvision_models.py", line 225, in densenet169
    model = load_pretrained(model, num_classes, settings)
  File "/opt/conda/lib/python3.8/site-packages/pretrainedmodels/models/torchvision_models.py", line 118, in load_pretrained
    state_dict = model_zoo.load_url(settings['url'])
  File "/opt/conda/lib/python3.8/site-packages/torch/hub.py", line 553, in load_state_dict_from_url
    download_url_to_file(url, cached_file, hash_prefix, progress=progress)
  File "/opt/conda/lib/python3.8/site-packages/torch/hub.py", line 419, in download_url_to_file
    u = urlopen(req)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/opt/conda/lib/python3.8/urllib/request.py", line 563, in error
    result = self._call_chain(*args)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/opt/conda/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/opt/conda/lib/python3.8/urllib/request.py", line 1397, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/opt/conda/lib/python3.8/urllib/request.py", line 1357, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1131)>

qaohv avatar Jul 06 '22 07:07 qaohv

您的邮件已收到!

Fzz123 avatar Jul 06 '22 07:07 Fzz123

Solution: import ssl ssl._create_default_https_context = ssl._create_unverified_context

Originally posted in https://github.com/Cadene/pretrained-models.pytorch/issues/193#issuecomment-635730515

chAwater avatar Jul 27 '22 02:07 chAwater