首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

tornado下https配置

问题背景

越来越多的网站已经支持https,相比于http更安全。尤其有的开发网站只支持https,例如微信公众平台。这里暂时不提tornado如何搭建https服务,回头有时间再记一下。

SSLError

可以用发送一个简单的https请求

https_url="https://path"https_client=AsyncHTTPClient()response=yieldYieldTask(token_client.fetch,access_token_url)

结果出现了如下问题

参考tornado rejects valid SSL certificates

这个原因是因为证书设置不正确,那么我们可以通过下面的操作给AsyncHTTPClient设置证书。

importcertifi AsyncHTTPClient.configure(None,defaults=dict(ca_certs=certifi.where()))

但是这个设置以后,会发现虽然不报错了,但是请求还是会失败,错误原因依然是

查看了certifi的主页certifi

发现官方也给出了解释:

Unfortunately, old versions of OpenSSL (less than 1.0.2) sometimesfail to validate certificate chains that use the strong roots. Forthis reason, if you fail to validate a certificate using thecertifi.where() mechanism, you can intentionally re-add the 1024-bitroots back into your bundle by calling certifi.old_where() instead.This is not recommended in production: if at all possible you shouldupgrade to a newer OpenSSL. However, if you have no other option, thismay work for you.

其实大概就是因为openssl的老版本(地域1.0.2)用的校验是strong roots(指的是只信任了少部分ca吗?我也没太懂)。总之,有好几个解决方法:1、换老版本的certifi来解决(因为老版本的certifi证书比较老,跟老版本的openssl正好合得来),但是这种方法不是非常好,目前看网上用的是版本,这个版本也没有certifi.old_where(),因为本身就是老的……

2、就用新版本的certifi,但是验证时用certifi.old_where()下面的证书来进行配置

importcertifiAsyncHTTPClient.configure(None,defaults=dict(ca_certs=certifi.old_where()))

3、升级python版本到2.7.9以上,因为这之后,python进行https请求时,不用再通过certifi来配置,而是已经内置了相关的证书。

4、升级openssl到1.0.2及以上。

推荐升级openssl或者Python版本,如果因为环境限制,实在没办法的话用old_where也行。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190220A008CI00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券