Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL: CERTIFICATE_VERIFY_FAILED while trying to download pretrained model #33288

Closed
muxgt opened this issue Feb 13, 2020 · 30 comments · Fixed by Fannovel16/comfyui_controlnet_aux#116
Assignees

Comments

@muxgt
Copy link

muxgt commented Feb 13, 2020

🐛 Bug

Trying to use pretrained model from torchvision and receiving urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)> when downloading. In similar issues #33233 and #33234 it was said that problem is solved but I'm facing the issue right now.

To Reproduce

vgg16 = torchvision.models.vgg16(pretrained=True)

Expected behavior

Pre-trained models should be downloaded without certificate failures

Environment

PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.12.0

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.0.130
GPU models and configuration: GPU 0: Tesla P100-PCIE-16GB
Nvidia driver version: 418.67
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip3] numpy==1.17.5
[pip3] torch==1.4.0
[pip3] torchfile==0.1.0
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.3.1
[pip3] torchvision==0.5.0
[conda] Could not collect



cc @ezyang @gchanan @zou3519
@Archetype90
Copy link

Same thing when trying to pip install pytorch:

pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

@Mxbonn
Copy link

Mxbonn commented Feb 13, 2020

I'm having the same issue just now.
Check pytorch/vision#1876 for the main issue in the torchvision repository.

@Aquassaut
Copy link

@Mxbonn I don't think it is the same issue. This issue is that the SSL certificate for download.pytorch.org expired today :)

@xen0f0n
Copy link

xen0f0n commented Feb 13, 2020

@Mxbonn @Archetype90 until the certificate gets renewed, you can download the .whl you need from here and install it using pip.

@optimuspaul
Copy link

@xen0f0n that doesn't help us download pertained models. Our entire inference pipeline is dead in the water right now because we can't download the models.

@albanD
Copy link
Collaborator

albanD commented Feb 13, 2020

You can use the same trick of using http instead of https as a temporary workaround.

@Lissanro
Copy link

Lissanro commented Feb 13, 2020

I encountered the same issue when downloading resnet152 after calling cnn_learner(data, models.resnet152, metrics=error_rate). As a workaround, I downloaded it manually without checking certificate (using http instead of https is another option):

cd ~/.cache/torch/checkpoints/
wget -c --no-check-certificate https://download.pytorch.org/models/resnet152-b121ed2d.pth

@albanD
Copy link
Collaborator

albanD commented Feb 13, 2020

Should be fixed now. Can you confirm it works for you?

@soumith
Copy link
Member

soumith commented Feb 13, 2020

The SSL Certificate issue is fixed now. The Cert was expired for ~4 hours, and we root-caused the auto-renewal problem, it wont happen again.

@soumith soumith closed this as completed Feb 13, 2020
@Neoanarika
Copy link

Hi, I am having the same issue today on Mac OS X 10.14.6 when I tried to install pre-trained model of VGG.

@jiangyuang
Copy link

jiangyuang commented May 29, 2020

I'm having the issue again while trying to download Resnet18 (Edit: it has a problem on MacOS but fine on Ubuntu)

@stephenllh
Copy link

stephenllh commented Jun 3, 2020

Having the same issue today when trying to download SEResNeXt-32x4d.

@mukultater
Copy link

Having issues in downloading se_resnext50_32x4d(),
SSL expired.!
WhatsApp Image 2020-06-04 at 12 35 26 AM
WhatsApp Image 2020-06-04 at 12 36 12 AM

WhatsApp Image 2020-06-04 at 12 35 03 AM

@hot9cups
Copy link

hot9cups commented Jun 8, 2020

I have the issue while trying to download Inception resnet V2

!pip install pretrainedmodels
!pip install efficientnet-pytorch
from pretrainedmodels.models.inceptionresnetv2 import inceptionresnetv2
model_transfer = inceptionresnetv2(pretrained='imagenet')

I ran this on colab
The following was the output:
image

But, when I set pretrained = False, the model gets downloaded just fine.
How do I solve this?

@will-maclean
Copy link

Same issue downloading pre-trained vgg

@hot9cups
Copy link

Okay, my problem didn't have to do with PyTorch itself, I was downloading the model from Cadenn, and that has some problems with the certificate.
A workaround to that is mentioned here
With that, my problem was solved, might help someone else as well.

@bdthombre
Copy link

Same issue persistent while downloading torchvison.models.resnet18(pretrained= True)

@bellship24
Copy link

bellship24 commented Jan 22, 2021

I got the Same issue

  • This is My code
    model = models.densenet121(pretrained=True)

  • There are error logs
    Traceback (most recent call last):
    File "xxxxxx/model.py", line 35, in
    model = models.densenet121(pretrained=True)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torchvision/models/densenet.py", line 236, in densenet121
    return _densenet('densenet121', 32, (6, 12, 24, 16), 64, pretrained, progress,
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torchvision/models/densenet.py", line 222, in _densenet
    _load_state_dict(model, model_urls[arch], progress)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torchvision/models/densenet.py", line 208, in _load_state_dict
    state_dict = load_state_dict_from_url(model_url, progress=progress)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/hub.py", line 555, in load_state_dict_from_url
    download_url_to_file(url, cached_file, hash_prefix, progress=progress)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/hub.py", line 425, in download_url_to_file
    u = urlopen(req)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
    raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>

@avico78
Copy link

avico78 commented Mar 29, 2021

Same issue with installing torch:

File "/usr/local/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 159, in iter
for x in it:
File "/usr/local/lib/python3.8/site-packages/pip/_internal/network/utils.py", line 64, in response_chunks
for chunk in response.raw.stream(
File "/usr/local/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/lib/python3.8/contextlib.py", line 131, in exit
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 449, in _error_catcher
raise SSLError(e)
pip._vendor.urllib3.exceptions.SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption failed or bad record mac (_ssl.c:2624)

@murthyn
Copy link

murthyn commented Oct 16, 2021

Same issue with downloading CIFAR10:

import torchvision

torchvision.datasets.CIFAR10(root='cifar10' + '/data', train=True, download=True)

causes

Traceback (most recent call last):
  File "download_cifar10.py", line 3, in <module>
    cifar_trainset = torchvision.datasets.CIFAR10(root='cifar10' + '/data', train=True, download=True)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/datasets/cifar.py", line 65, in __init__
    self.download()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/datasets/cifar.py", line 143, in download
    download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/datasets/utils.py", line 413, in download_and_extract_archive
    download_url(url, download_root, filename, md5)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/datasets/utils.py", line 129, in download_url
    url = _get_redirect_url(url, max_hops=max_redirect_hops)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/datasets/utils.py", line 77, in _get_redirect_url
    with urllib.request.urlopen(urllib.request.Request(url, headers=headers)) as response:
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1393, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1352, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)>

@adityasaini70
Copy link

adityasaini70 commented Oct 28, 2021

If anyone's short of time and can't wait till this is fixed, they can use the following hack: Just put these lines at the top of your codebase, and then run the same code again

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Link: https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3#answer-49174340

@AbhishekMaruturiVH
Copy link

If anyone's short of time and can't wait till this is fixed, they can use the following hack: Just put these lines at the top of your codebase, and then run the same code again

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Link: https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3#answer-49174340

Thanks @adityasaini70 , This worked. Can you explain what we did here?

@BenjaminPoole
Copy link

@adityasaini70, Thanks this worked for me as well.

@danton721
Copy link

danton721 commented Apr 3, 2022

The SSL Certificate issue is fixed now. The Cert was expired for ~4 hours, and we root-caused the auto-renewal problem, it wont happen again.

it happened, https://download.pytorch.org/ seems to have invalid certificates again, just letting you know

@knimet
Copy link

knimet commented Apr 3, 2022

same issue

@shengkunc
Copy link

shengkunc commented Apr 3, 2022

hit the same now, WAR still works:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

@RachitBansal
Copy link

Yes, facing the same issue while downloading resnet50.
@adityasaini70's solution still works.

@lamoboos223
Copy link

the issue is back again

@yassineAlouini
Copy link

This is the best and fastest workaround for this recurrent issue:

#33288 (comment)

@keshiriotinto
Copy link

If anyone's short of time and can't wait till this is fixed, they can use the following hack: Just put these lines at the top of your codebase, and then run the same code again

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Link: https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3#answer-49174340

Still works in 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet