python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool

 

代码运行后

SSLError: HTTPSConnectionPool(host='b-ssl.duitang.com', port=443): 

Requests 可以为 HTTPS 请求验证 SSL 证书,就像 web 浏览器一样。SSL 验证默认是开启的,如果证书验证失败,Requests 会抛出 SSLError:

第一种解决方法:

 将verify 设置为 False,Requests 将忽略对 SSL 证书的验证

 

 
  • import requests
    
    url='https://www.duitang.com/napi/blog/list/by_search/?kw=%E6%A0%A1%E8%8A%B1&start=0&limit=1000'
    
    page=requests.get(url,verify=False)

    正确的做法

  1. 参考

https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

 

https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl

 

 

Certificate verification

 

It is highly recommended to always use SSL certificate verification.By default, urllib3 does not verify HTTPS requests.

In order to enable verification you will need a set of root certificates. The easiestand most reliable method is to use thecertifi package which provides Mozilla’s root certificate bundle:

pip install certifi

 

安装几个包

 

pip install cryptography

 

pip install pyOpenSSL

 

pip install certifi

Trust Database for Humans

 

Certifi is a carefully curated collection of Root Certificates forvalidating the trustworthiness of SSL certificates while verifying theidentity of TLS hosts. It has been extracted from theRequests project.

The internet is an untrusted place. Every HTTP request you make should haveverification on by default. This happens every time you access a website withyour web browser, without any knowledge to the user — there’s no reason yourcode should be any different.

Certifi is here to make this possible.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值