问题描述
- python2中requests.post能否做双向认证?需要的证书一般从哪里获得?
-
如题,纠结了好久了。用socket和openssl方式通过2各pem文件可以实现认证,但是换成requests.post方式就不行了。成功的函数如下:def ssl_request(data=None): import OpenSSL ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) ctx.use_certificate_file('/Users/username/Work/cert.pem') # 证书 ctx.use_privatekey_file('/Users/username/Work/key-unencrypted.pem') # 密钥 sock = socket.socket() ssock = OpenSSL.SSL.Connection(ctx, sock) ssock.connect(('123.456.789.111', 443)) send_flag = 1 while send_flag == 1: try: ssock.send(data) send_flag = 0 except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError): continue write_flag = 1 while write_flag == 1: try: recv_data = ssock.recv(16384) write_flag = 0 except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError): continue sock.close() return recv_data
解决方案
用request post做双向认证的错误是什么,是不是你的证书没有配置正确
时间: 2024-10-26 05:26:41