博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tornado下https配置
阅读量:7183 次
发布时间:2019-06-29

本文共 1620 字,大约阅读时间需要 5 分钟。

问题背景

越来越多的网站已经支持https,相比于http更安全。尤其有的开发网站只支持https,例如微信公众平台。

这里暂时不提tornado如何搭建https服务,回头有时间再记一下。

SSLError

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

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

结果出现了如下问题

ssl.SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

参考

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

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

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

查看了certifi的主页

发现官方也给出了解释:

Unfortunately, old versions of OpenSSL (less than 1.0.2) sometimes

fail to validate certificate chains that use the strong roots. For
this reason, if you fail to validate a certificate using the
certifi.where() mechanism, you can intentionally re-add the 1024-bit
roots back into your bundle by calling certifi.old_where() instead.
This is not recommended in production: if at all possible you should
upgrade to a newer OpenSSL. However, if you have no other option, this
may work for you.

其实大概就是因为openssl的老版本(地域1.0.2)用的校验是strong roots(指的是只信任了少部分ca吗?我也没太懂)。总之,有好几个解决方法:

1、换老版本的certifi来解决(因为老版本的certifi证书比较老,跟老版本的openssl正好合得来),但是这种方法不是非常好,目前看网上用的是certifi==2015.04.28版本,这个版本也没有certifi.old_where(),因为本身就是老的……

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

import certifiAsyncHTTPClient.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也行。

转载地址:http://gpykm.baihongyu.com/

你可能感兴趣的文章
css02
查看>>
Hot Standby 与 Stream Replication
查看>>
【ZZ已解决】Python中如何在嵌套函数内部访问被嵌套(的父级函数)中的(局部,非全局)变量...
查看>>
一款jQuery满屏自适应焦点图切换特效
查看>>
python技能(2)-sys.argv
查看>>
NFS 安装问题解决
查看>>
对 Sea.js 进行配置 seajs.config
查看>>
我几次求职经验谈--智联相伴
查看>>
PHP中文乱码问题总结[转]
查看>>
IPv6系列-入门指南
查看>>
spring学习笔记(二)
查看>>
DNS智能解析的另类使用 让搜索引擎更快更好的收录您的网站
查看>>
转:java操作文件
查看>>
工具系列——eslint的使用
查看>>
思科IOS配置五大技巧
查看>>
phpwind 论坛迁移过程
查看>>
14个Web移动编程视频网站资源分享
查看>>
我的友情链接
查看>>
nonatomic,assign,copy,retain的区别(转)
查看>>
ubuntu 18.04 docker 学习经历(三)Docker mysql 及 phpmyadmin
查看>>