python request

1.去掉https的ssl安全验证

在get或post请求中verify=False

例如

requests.get(url, verify=False)

 

2.解决Python3 控制台输出InsecureRequestWarning的问题

使用Python3 requests发送HTTPS请求,已经关闭认证(verify=False)情况下,控制台会输出以下错误:

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

 解决方法:

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

3.设置代理
requests.adapters.DEFAULT_RETRIES = 5  # 增加重连次数
s = requests.session()
s.keep_alive = False # 关闭多余连接
s.proxies = {"https": "124.207.82.166:8008", "http": "119.57.108.109:5328", }
posted @ 2019-01-14 13:17  M兔  阅读(355)  评论(0编辑  收藏  举报