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

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: