我在Linux机器上使用Python 3.6。我的HTTPS请求不起作用。
import requests
requests.get('https://192.168.56.101:4665/v1/objects/services/docker-icinga2!random-005', verify=False, auth=('root', 'icinga'))
回复是:
/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:852: 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
InsecureRequestWarning)
使用disable_warnings 所以代码:
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable flag warning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
requests.get('https://192.168.56.101:4665/v1/objects/services/docker-
icinga2!random-005', auth=('root', 'icinga'))
我得到这个作为回应(你在图片中看到) Error
答案 0 :(得分:0)
要禁用此警告,您可以使用requests.package.disable_warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable flag warning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
requests.get('https://192.168.56.101:4665/v1/objects/services/docker-icinga2!random-005', verify=False, auth=('root', 'icinga'))