preface
Sslerror: Certificate verify failed is sometimes encountered in the automation of Internet discovery interface. It is very interesting, so it is recorded
code
import urllib.request
weburl = "https://www.douban.com/"
webheader = {
'Accept': 'text/html, application/xhtml+xml, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
}
req = urllib.request.Request(url=weburl, headers=webheader)
webPage = urllib.request.urlopen(req)
data = webPage.read().decode('utf-8')
Error message
In the python implementation automation interface request, when an HTTPS link is opened using urllib.urlopen, the SSL certificate will be verified once. This exception will be thrown when the target website uses a self signed certificate:
urllib2.URLError: < urlopen error [SSL: CERTIFICATE_ VERIFY_ FAILED] certificate verify failed (_ ssl.c:590)
modify
requests.get(url, params=None, verify=False)
requests.post(url, data=None, json=None, verify=False)
Another question
After we modify according to the above method, another problem will arise (we passed the test, but there is a warning that the final test report is not beautiful, as shown in the figure below) )
terms of settlement
We can add the following code under the encapsulated requests module
import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
After executing the test case again, a beautiful test report is generated
Similar Posts:
- Nltk’s word splitter Punkt: SSL problem, unable to download
- You-get Warning urllib.error.URLError:
- Differences of urllib, urllib2, httplib and httplib2 libraries in Python
- Python3 Use urlliburlopen error EOF occurred in violation of protocol (_ssl.c:841)
- Python Ssl.certificateerror errors [How to Solve]
- How to Solve Python Error: “HTTP Error 403: Forbidden”
- [Solved] HTTP Error 301: The HTTP server returned a redirect error that would lead to an infinite loop.
- Python uses urllib package to request HTTPS error [How to Solve]
- Python crawling picture prompt urllib.error.httperror: http error 403: forbidden solution
- Python 2.7 and 3.4 requests Error: No module named ‘zlib’