python,

Disable "InsecureRequestWarning: Unverified HTTPS request is being made" in Python

Nov 17, 2022 · 1 min read · Post a comment

It’s not so common to be concerned about HTTPS endpoints in the development stage. Thus, it feels like suppressing warning messages is a common thing, right. So, as I was playing around with a dockerized Python app I was getting: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. warning again and again. Here are few things you could try to disable this specific warning.

Prerequisites

  • Python 3
  • Python packages: urllib3, requests

Solution(s)

Python 3 code update

Insert the following code:

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

If you want to disable all warnings, add this instead:

from requests.packages import urllib3
urllib3.disable_warnings() 

env vars

Set an env variable in Linux / MacOS:

export PYTHONWARNINGS="ignore:Unverified HTTPS request"

PowerShell:

$env:PYTHONWARNINGS="ignore:Unverified HTTPS request"

Conclusion

Strongly recommended not to apply it in a production environment. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.