3 Examples to Fix InsecureRequestWarning in Python

Table of Contents

These InsecureRequestWarning warning messages show up when a request is made to an HTTPS URL without certificate verification enabled.

we will cover how to fix InsecureRequestWarning with 3 examples in this article.

We will skip the SSL certificate check in the first and second examples. For the third example, we will add the CA bundle in the code to check the SSL certificate.

Fix InsecureRequestWarning in Python urllib3

from urllib3.exceptions import InsecureRequestWarning
from urllib3 import disable_warnings
disable_warnings(InsecureRequestWarning)

 

Fix InsecureRequestWarning in Python requests

import requests
response = requests.get(url=”, verify=False)

the error message is below:

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.

add the following codes to fix it

import requests
requests.packages.urllib3.disable_warnings()

 

Fix InsecureRequestWarning in Python requests with CA Bundle

Go to http://certifiio.readthedocs.io/en/latest/ to get the Raw CA Bundle

  • Download the raw CA Bundle in Click How do I use it? in that page and put this file in the project directory
  • Modify the storage path of the file downloaded in the previous step

requests.post(url=API_SERVER, headers=headers, data=json.dumps(data), verify=’CA_PATH‘)

Table of Contents

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

You might also like