pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.13k stars 6.94k forks source link

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1122) #5311

Open pevogam opened 2 years ago

pevogam commented 2 years ago

🐛 Describe the bug

When downloading weights data from the PyTorch hub we get the following:

[stdlog] 2022-01-27 14:41:18,434 client           L0864 INFO | Traceback (most recent call last):
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\site-packages\torchvision\models\detection\faster_rcnn.py", line 369, in fasterrcnn_resnet50_fpn
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |     state_dict = load_state_dict_from_url(model_urls['fasterrcnn_resnet50_fpn_coco'],
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\site-packages\torch\hub.py", line 524, in load_state_dict_from_url
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |     download_url_to_file(url, cached_file, hash_prefix, progress=progress)
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\site-packages\torch\hub.py", line 394, in download_url_to_file
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |     u = urlopen(req)
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 214, in urlopen
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |     return opener.open(url, data, timeout)
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 517, in open
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |     response = self._open(req, data)
[stdlog] 2022-01-27 14:41:18,435 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 534, in _open
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |     result = self._call_chain(self.handle_open, protocol, protocol +
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 494, in _call_chain
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |     result = func(*args)
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 1385, in https_open
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |     return self.do_open(http.client.HTTPSConnection, req,
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |   File "C:\Program Files\Python39\lib\urllib\request.py", line 1345, in do_open
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO |     raise URLError(err)
[stdlog] 2022-01-27 14:41:18,436 client           L0864 INFO | urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1122)>

whereby checks of the certificate validity passed and this issue only happens on Windows (tested the same code on Linux without any problem). Downloading the same data file from a browser works fine (don't mind the loaded page, I loaded download.pytorch.org at first):

image

Versions

C:>python.exe collect_env.py Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure. It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe Collecting environment information... PyTorch version: N/A Is debug build: N/A CUDA used to build PyTorch: N/A ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Enterprise 2016 LTSB GCC version: Could not collect Clang version: Could not collect CMake version: Could not collect Libc version: N/A

Python version: 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] (64-bit runtime) Python platform: Windows-10-10.0.14393-SP0 Is CUDA available: N/A CUDA runtime version: Could not collect GPU models and configuration: Could not collect Nvidia driver version: Could not collect cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] Could not collect [conda] Could not collect

cc @peterjc123 @nbcsm @guyang3532 @maxluk @gunandrose4u @mszhanyi

datumbox commented 2 years ago

Similar SSL verification problems have been popping up for a while now. Unfortunately that is not related to TorchVision but rather caused by issues on the S3 side where we store the weights. It's also something we can reproduce consistently as it depends on the region from which you try to access the weights.

I suspect that if you test this again a few hours later the issue might be resolved. Let me know if that's the case.

pevogam commented 2 years ago

The surprising thing is that I don't have this problem on Linux from the same region, only on a Windows machine.