MPContribs API: certificate verify failed despite correct env variable

Hi all,

I am getting the error

twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>]

described on mpcontribs-client · PyPI despite having set the correct environment variable (and having verified that it is indeed set using os.getenv).
I also tried getting a new API key by setting up a new account on MPContribs but no success.

Is this just me or does anyone have an idea how to fix it?



You are using the API key from and not your regular API key, right?

Can you post code to minimally reproduce your error?

I am able to

from mpcontribs.client import Client
client = Client()

without issue.

There seems to be discussion of your error in the link you gave relating to properly setting a SSL_CERT_FILE environment variable. However, this variable is not set on my system. Perphaps this error is operating-system specific? What is your setup? I am, for example, using a conda Python environment on MacOS 10.15.

Hi Donny,

thanks very much for the quick reply!
Yes, I am using the contribs API key you get when logging in at MPcontribs and hovering over the user icon (I think it’s about double the length of the MP API key).

Here is part of my code

from pymatgen.ext.matproj import MPRester
from mpcontribs.client import Client
(further imports)

class MPRequests:
    def __init__(self, api_key, contribs_api_key=None, include_non_icsd=True):
        self.api_key = api_key
        self.contribs_api_key = contribs_api_key
        self.include_non_icsd = include_non_icsd
        self.mpr = MPRester(self.api_key)
        self.contribs_client = Client(apikey=contribs_api_key)

    def add_transport_properties(self):
        name = "carrier_transport"
        resp = self.contribs_client.contributions.get_entries(
             project=name, identifier="mp-1992", _fields=["id"]
        return resp

I am using a Portable Python environment on Win 10. The “normal” MP rester and pymatgen work just fine.

Hi Josua,

the SSL errors are related to issues with certificate locations/installations on Windows. Setting SSL_CERT_FILE to $(python -m certifi) usually takes care of it on Windows. There’s some info about python on Windows and setting environment variables here. I unfortunately don’t have access to a Windows machine to try and reproduce this for your specific environment but I’m testing the client initialization as part of MPContribs Github actions before releasing to PyPI. The latest test for 3.10.1 seems to work fine. Which version of the mpcontribs-client are you using?

PS: I recommend using the MPCONTRIBS_API_KEY environment variable to set the API key instead of the keyword argument in the constructor.


Hi Patrick,

thanks a lot! Unfortunately, for some reason setting the environment variable did not do the trick. Doesn’t matter which way I tried to set it. I am using mpcontribs-client 3.10.1 and also tried unstalling and re-installing it.
This may very well have to do with my somewhat odd environment on Windows. For now, we can avoid this issue by downloading the data we need locally and using that. Maybe we should switch to a Linux-based workstation at some point anyway. :wink:

Thanks a lot anyway for your help!