Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1109441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:14:09+00:00 2026-05-17T02:14:09+00:00

M2Crypto raises a TypeError when loading SSL CA certificates. I’m getting the path of

  • 0

M2Crypto raises a TypeError when loading SSL CA certificates. I’m getting the path of an SSL certificate from an instance of a Django model. My code worked perfectly because I was pulling the path of the certificate from a Django model

My code:

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)

Raises:

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 *'

However this code works fine

from M2Crypto import SSL
ctx = SSL.Context()
ctx.load_verify_locations('/path/to/my/certificates/certificate.cer')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:14:10+00:00Added an answer on May 17, 2026 at 2:14 am

    Just worked it out!

    The load_verify_locations() function is expecting a string object, not a unicode object.

    Django uses unicode by default, so the certificate path needs to be converted to a string before passed into load_verify_locations(). So:

    ctx.load_verify_locations(str(m.ca_file))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my Python code, I can successfully encrypt and decrypt using M2Crypto: from
How to set compression method for SSL/TLS connection created with M2Crypto and TwistedProtocolWrapper
I'm making a secure SSL connection to a server using python and M2Crypto. See
The M2Crypto library has a few CA-related functions on its SSL.Context object , but
I would like to use the button encryption in django-paypal, but it requires M2Crypto
I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and
Could anybody explain what is the cause of the following: >>> from M2Crypto import
I am tasked with migrating a server's networking from plain sockets to SSL in
I am having a hard time running a M2Crypto SSLServer with EXPORT grade ciphers.
I'm trying to build and install M2Crypto on Ubuntu 10.04 LTS. I downloaded and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.