[Python] 用 requests 出現 InsecureRequestWarning

Posted in :

在換到 requests 之後,因為他使用 urllib3,就會對 https 的網址出現以下警告:

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

解法:

So i got the solution to hide the warning. Here is what i did.

import warnings
from urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter('ignore',InsecureRequestWarning)

warnings.simplefilter('ignore',InsecureRequestWarning)
requests.get('https://github.com/',verify=False)

And this thing solved my problem.


相關文章:

requests 使用方法:
https://requests.readthedocs.io/en/master/

>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'private_gists': 419, u'total_private_repos': 77, ...}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *