howtouselinux

3 Ways 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. We can 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

Advertisements
  • 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‘)

Facebook
Twitter
LinkedIn

Loom is a video messaging tool that helps you get your message across through instantly shareable videos.

With Loom, you can record your camera, microphone, and desktop simultaneously. Your video is then instantly available to share through Loom’s patented technology.