使用python访问具有PKI安全性的网站

使用python访问具有PKI安全性的网站,第1张

使用python访问具有PKI安全性的网站

我创建了一个PKI处理程序来处理请求,因此可以在urllib2库中使用它。

import httplib, urllib2class HTTPSClientAuthHandler(urllib2.HTTPSHandler):    def __init__(self, key, cert):        urllib2.HTTPSHandler.__init__(self)        self.key = key        self.cert = cert    def https_open(self, req):        #Rather than pass in a reference to a connection class, we pass in        # a reference to a function which, for all intents and purposes,        # will behave as a constructor        return self.do_open(self.getConnection, req)    def getConnection(self, host, timeout=300):        return  httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert, timeout=timeout)

要使用此功能,您将需要在处理程序中使用cookiejar。

from cookielib import cookieJarcookiejar = cookieJay()handlers = []handlers.append(HTTPSClientAuthHandler(somekey, somecert))handlers.append(urllib2.HTTPcookieProcessor(cookiejar))opener = urllib2.build_opener(*handlers)... do other urllib2 calls ....

希望这对大家有帮助!



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5650160.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存