python HTTPSconnection SSL 访问https
2015-12-23 10:05
465 查看
在做一些敏感信息交互中往往需要使用到https来加强信息安全性。
交互双方需要交换RAS密钥,进行数据的加密和校验。
今天需要使用http SSL通道来传输数据,所以写下来做个备忘。
不需要特定的私钥文件(在跟使用urllib2.urlopen()差不多),代码如下:
需要使用到特定证书的方式(.pem证书),代码如下
交互双方需要交换RAS密钥,进行数据的加密和校验。
今天需要使用http SSL通道来传输数据,所以写下来做个备忘。
不需要特定的私钥文件(在跟使用urllib2.urlopen()差不多),代码如下:
httpsConn = httplib.HTTPSConnection("www.baidu.com") httpsConn.request("GET", "/") res = httpsConn.getresponse() print res.status, res.reason, res.read()
需要使用到特定证书的方式(.pem证书),代码如下
# coding=utf8 import ssl import Properties from httplib import HTTPSConnection import base64 def send(path): port = Properties.SSLPORT host = Properties.HOST url = host + ":" + str(port) + path context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.load_cert_chain(Properties.PRIVATE_KEY, **{"password":Properties.PASSWORD}) data = '123' httpsConn = HTTPSConnection(host, port, None, None, "", 60000, "", context) httpsConn.request("POST", path, data, {"Authorization": "Basic " + base64.encodestring("12345678")}) res = httpsConn.getresponse() print res.status,res.reason, res.getheaders(), res.read() if __name__=="__main__": """ httpsConn = httplib.HTTPSConnection("www.baidu.com") httpsConn.request("GET", "/") res = httpsConn.getresponse() print res.status, res.reason, len(res.read()) """ send("/post")
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法