启动python终端会话失败_python2.7中的SSL会话缓存失败

我试图使用python设置一个HTTPS服务器,但是SSL会话缓存不起作用。这是一个最小的复制品。证书是我用openssl命令行生成的一个简单的自签名证书和密钥。在from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

import ssl

context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)

context.load_cert_chain("cert.pem", "cert.key")

old_hits = 0

old_misses = 0

class myHTTPHandler(BaseHTTPRequestHandler):

def do_GET(s):

global old_hits,old_misses

hits = context.session_stats()['hits']

misses = context.session_stats()['misses']

hitmiss = "Cache hit" if hits>old_hits else ("Cache miss" if misses>old_misses else "Resumption not requested")

old_hits = hits

old_misses = misses

body = "You requested: {}; {}\n".format(s.path,hitmiss)

s.send_response(200)

s.send_header("Content-type", "text/html")

s.send_header("Content-Length", str(len(body)))

s.end_headers()

s.wfile.write(body)

httpd = HTTPServer(('',4434),myHTTPHandler)

httpd.socket = context.wrap_socket(httpd.socket, server_side=True)

httpd.serve_forever()

我使用以下curl命令行进行测试:

^{pr2}$

结果是:You requested: /; Resumption not requested

You requested: /; Cache miss

You requested: /; Cache miss

谢谢。在

环境:在现有的Ubuntu上运行

Python 2.7.12版

OpenSSL 1.0.2g

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值