urllib.error.URLError: < urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certi
Solution:
Add the following two lines of code before the code starts:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
Complete example:
import torch
import torchvision
import torchvision.transforms as transforms
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
#Download the data set and adjust the image, because the output of the torchvision data set is in PILImage format, and the data field is in [0,1]
#We convert it into the tensor format of the standard data field [-1,1]
#transform Data Converter
transform=transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])
trainset=torchvision.datasets.CIFAR10(root='./data',train=True,download=True,transform=transform)
# The downloaded data is placed in the trainset
trainloader=torch.utils.data.DataLoader(trainset,batch_size=4,shuffle=True,num_workers=2)
# DataLoader Data Iterator Encapsulate data into DataLoader
# num_workers: Two threads read data
# batch_size=4 batch processing
testset=torchvision.datasets.CIFAR10(root='./data',train=False,download=True,transform=transform)
testloader=torch.utils.data.DataLoader(testset,batch_size=4,shuffle=False,num_workers=2)
classes=('airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
Download result
Read More:
- urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
- [Solved] urllib.error.URLError: <urlopen error [SSL: WRONG_VERSION_NUMBER] wrong version number
- [Solved] urllib.error.URLError: urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]
- Error when downloading the built-in dataset of pytoch = urllib.error.urlerror: urlopen error [SSL: certificate_verify_failed]
- Pytorch Run Error: BrokenPipeError [How to Solve]
- [Solved] raise ContentTooShortError(urllib.error.ContentTooShortError: <urlopen error retrieval incomplete:
- How to Solve Pytorch eval Stuck Error
- [Solved] PyTorch Caught RuntimeError in DataLoader worker process 0和invalid argument 0: Sizes of tensors mus
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- [Solved] Pytorch Error: RuntimeError: Error(s) in loading state_dict for Network: size mismatch
- Python Error: certificate verify failed: certificate has expired
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…
- python chatterbot [nltk_data] Error loading stopwords: <urlopen error [Errno 11004]
- SSL error of urllib3 when Python uploads files using Minio
- Python 3 urllib has no URLEncode attribute
- RTX 3090 Run pytorch Error: CUDA error: no kernel image is available for execution on the device
- pytorch model.load_state_dict Error [How to Solve]