M2Crypto 在加载 SSL CA 证书时引发 TypeError。我从 Django 模型的实例中获取 SSL 证书的路径。我的代码运行良好,因为我从 Django 模型中提取证书的路径
我的代码:
from M2Crypto import SSL
from django.db import models
class MyModel(models.Model):
ca_file = models.FilePathField(path='/path/to/my/certificates/')
m = MyModel(ca_file='/path/to/my/certificates/certificate.cer')
m.save()
ctx = SSL.Context()
ctx.load_verify_locations(m.ca_file)
提高:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/django/lib/datalivelib/utils/https.py", line 51, in do_https
if ctx.load_verify_locations(ca_file) != 1:
File "/usr/lib/pymodules/python2.6/M2Crypto/SSL/Context.py", line 131, in load_verify_locations
return m2.ssl_ctx_load_verify_locations(self.ctx, cafile, capath)
TypeError: in method 'ssl_ctx_load_verify_locations', argument 2 of type 'char const *'
但是这段代码工作正常
from M2Crypto import SSL
ctx = SSL.Context()
ctx.load_verify_locations('/path/to/my/certificates/certificate.cer')