HTTPS Python客户端

2024-10-01 13:24:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个tornado服务器,它提供了一个https连接和一个我用这种方式生成的自签名证书:

openssl genrsa -out privatekey.pem 1024                                         
openssl req -new -key privatekey.pem -out certrequest.csr 
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

服务器代码如下:

^{pr2}$

我希望有一个python客户机连接到服务器并检查服务器是否是正确的服务器(我通过它的证书猜测)。 目前,我做了一个简单的客户:

import httplib
HOSTNAME='localhost'
conn = httplib.HTTPSConnection(HOSTNAME)
conn.putrequest('GET','/')
conn.endheaders()
response = conn.getresponse()
print response.read()

你建议我怎么做(客户机稍后将成为移动应用程序我只使用python进行原型设计)?在

谢谢。在


Tags: 服务器客户机responseoutconnpemreqtornado