Tag Archives: ssl.CertificateError

Python Ssl.certificateerror errors [How to Solve]

Some websites do not obtain the security certificate issued by the browser. When you request this website, the browser will treat it as an unsafe website, so it will report ssl.certificate error

The solution is to modify the default certificate verification mode to no verification code, as follows:

from urllib import request
#Importing the authentication module
import ssl
# assign the default certificate validation mode to no validation
ssl._create_default_https_context = ssl._create_unverified_context
base_url = 'https://www.12306.cn/mormhweb/'
# initiate request
response = request.urlopen(base_url)
 
print(response.read().decode('utf-8'))

Finally, you will find that the error is not reported and the problem is solved