Solve the Python3 console output InsecureRequestWarning problem
- 2021-07-18 08:23:06
- OfStack
Solve the problem of InsecureRequestWarning output from Python3 console
Question:
When an HTTPS request is sent using Python3 requests and authentication has been turned off (verify=False), the console outputs the following error:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Solution:
Add the following code to the code to solve this problem:
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
Python2 can be solved by adding the following code:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable security request warning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
ps: The following is an introduction to python3 requests disable security request warning
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Disable security request warning
Console Output Remove SSL Authentication Warning
Summarize