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
Similar Posts:
- Nltk’s word splitter Punkt: SSL problem, unable to download
- MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors
- Python3 Use urlliburlopen error EOF occurred in violation of protocol (_ssl.c:841)
- How to Solve Python Error: “HTTP Error 403: Forbidden”
- Error in Python data fetching “[SSL: Certificate]_ VERIFY_ FAILED] certificate verify failed (_ The solution of “None” problem in SSL. C: 841
- Interface automation (8): an error is reported during interface testing sslerror: Certificate verify failed
- Differences of urllib, urllib2, httplib and httplib2 libraries in Python
- [Solved] HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop.
- [Solved] remote calling three-party interface error: javax.net.ssl.SSLHandshakeException
- Postman Error: Could not get any response [How to Solve]