Python和m2从字符串加载证书和私钥

2024-10-01 07:36:11 发布

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

你能帮我修m2crypto吗?

下面的代码是返回“HTTP/1.1 403 Forbidden”服务器。 代码中未加载证书和私钥:

from M2Crypto import Rand, SSL, httpslib, threading , BIO , X509 , RSA
ctx = SSL.Context('sslv23')
store = ctx.get_cert_store()
bio = BIO.MemoryBuffer()
bio.write( str( open( 'certi.pem', 'r' ).read() ) )
store.add_x509( X509.load_cert_bio(bio) )

# or
# store.add_x509( X509.load_cert_string( str(open( 'certi.pem', 'r' ).read()) ) )

ctx.set_verify( SSL.verify_none, depth=1 )    
ctx.set_info_callback()
h = httpslib.HTTPSConnection( ‘Server’, 443, ssl_context=ctx )
h.set_debuglevel(1)
h.request( 'mysoap' )

当我这么做的时候,它就起作用了:

^{pr2}$

谢谢


Tags: store代码sslreadcertopenpembio