Interface automation (8): an error is reported during interface testing sslerror: Certificate verify failed


Sslerror: Certificate verify failed is sometimes encountered in the automation of Internet discovery interface. It is very interesting, so it is recorded


import urllib.request

weburl = ""
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 ='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)


requests.get(url, params=None, verify=False), 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


  After executing the test case again, a beautiful test report is generated



Similar Posts: