Tag Archives: Problems encountered in writing pytorch

Error when downloading the built-in dataset of pytoch = urllib.error.urlerror: urlopen error [SSL: certificate_verify_failed]

Error reason:

This is an SSL certificate validation error. When an HTTPS site is requested, but the certificate validation error occurs, such an error will be reported.

Solution:

Just add the following two lines to the code to skip the certificate check and successfully access the web page.

# Global removal of certificate validation
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

AttributeError: type object ‘Image‘ has no attribute ‘open‘

AttributeError: type object ‘Image‘ has no attribute ‘open‘

Cause analysis: the calling sequence of image is wrong, because the from PIL import image in the first line conflicts with Tkinter import * in the second line, and Tkinter also contains image class, so you use tkinter.image

Solution: from PIL import image as IMIM

Original call sequence

try:
    from PIL import Image
except ImportError:
    import Image

import tkinter as tk
from tkinter import *
from tkinter import filedialog

Original call sequence

import tkinter as tk
from tkinter import *
from tkinter import filedialog

try:
    from PIL import Image
except ImportError:
    import Image