Python Error: certificate verify failed: certificate has expired

Let’s talk about the situation at that time. Because there is no cifar10 data set on this machine, when downloading cifar10 with the following code:

trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                        download=True, transform=transform)

Certificate verify failed: the error message certificate has expired appears.

Later, I found that the following two lines can be added to the file header:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Done! happy

Read More: