企业认证填坑
import pycurl import xml.etree.ElementTree as ET from cStringIO import StringIO
def postXmlSSL(self, xml, url, second=30, cert=True, post=True): """使用证书""" self.curl.setopt(pycurl.URL, url) self.curl.setopt(pycurl.TIMEOUT, second) # 设置证书 # 使用证书:cert 与 key 分别属于两个.pem文件 # 默认格式为PEM,可以注释 if cert: self.curl.setopt(pycurl.SSLKEYTYPE, "PEM") self.curl.setopt(pycurl.SSLKEY, os.getcwd()+'/static/data/cacert/apiclient_key.pem') self.curl.setopt(pycurl.SSLCERTTYPE, "PEM") self.curl.setopt(pycurl.SSLCERT, os.getcwd()+'/static/data/cacert/apiclient_cert.pem') # post提交方式 if post: self.curl.setopt(pycurl.POST, True) self.curl.setopt(pycurl.POSTFIELDS, xml) buff = StringIO() self.curl.setopt(pycurl.WRITEFUNCTION, buff.write) self.curl.perform() return buff.getvalue()
def xmlToArray(self, xml): """将xml转为array""" array_data = {} root = ET.fromstring(xml) for child in root: value = child.text array_data[child.tag] = value return array_data
self.response = CurlClient().postXmlSSL(xm_data, url, second=30) res = self.xmlToArray(self.response)
(58, 'unable to use client certificate (no key found or wrong pass phrase?)') 这个坑
认证中主要代码都在这里了,需要注意的pem文件的引入需要时绝对路径, 且直接下载使用即可