Twisted.python.failure Error

Hello all,

I’m attempting to setup a script to import some data from MP. I just have the following:

from mp_api import MPRester
myAPI = “myapistringhere”
with MPRester(myAPI) as mpr:

and then I just ran a simple command to read data in regarding a single material ID and print out a couple of details. The strange thing is that the data is successfully read in and the properties outputted, but before then I receive an error:

C:\Users\mynamehere\AppData\Local\Programs\Python\Python39\lib\site-packages\mp_api\ builtins.UserWarning: Problem loading MPContribs client: [<twisted.python.failure.Failure OpenSSL.SSL.Error: [(‘STORE routines’, ‘’, ‘unregistered scheme’), (‘system library’, ‘’, ‘’), (‘STORE routines’, ‘’, ‘unregistered scheme’), (‘STORE routines’, ‘’, ‘unsupported’), (‘STORE routines’, ‘’, ‘unregistered scheme’), (‘system library’, ‘’, ‘’), (‘STORE routines’, ‘’, ‘unregistered scheme’), (‘STORE routines’, ‘’, ‘unsupported’), (‘STORE routines’, ‘’, ‘unregistered scheme’), (‘system library’, ‘’, ‘’), (‘STORE routines’, ‘’, ‘unregistered scheme’), (‘STORE routines’, ‘’, ‘unsupported’), (‘SSL routines’, ‘’, ‘certificate verify failed’)]>]

I saw some suggestions to set SSL_CERT_FILE = $(python -m certifi) and did that to no avail. Does anyone know how to fix this error or whether I should just ignore it?

Hi there, you’re right that the error message is likely due to a problem with setting SSL_CERT_FILE correctly in your environment. Setting it to the certifi location should resolve it. Can you confirm that SSL_CERT_FILE is set to something like <my-python-env>/lib/python3.9/site-packages/certifi/cacert.pem, i.e. using the same package location as the python executable running your code?

Hi tschaume, thanks for the post.

It was set to SSL_CERT_FILE = $(python -m certifi). I double checked my python.exe location, which is in C:\Users\mynamehere\AppData\Local\Programs\Python\Python39. From there, I found the cacert.pem file following the path you mention and set my SSL_CERT_FILE to that entire path. I still got the same error unfortunately.

Ok good. Can you print the SSL_CERT_FILE env var in your python code just before you call MPRester? I want to make sure it’s set to what we’d expect it to be. Thanks!

I was finally able to solve it with that tip! I didn’t realize I needed to restart command prompt for the environmental variables to update (I thought they were loaded as needed I guess). I was fixing the problem and breaking it again while troubleshooting because I didn’t realize I needed to restart the command prompt.

Thanks for the help!

1 Like

Hello physopholy. I’m also getting the same error but unable to resolve it.
I also checked the location of python.exe that you said & also found cacert.pem file , now what to do next?

Can you try upgrading mpcontribs-client to its latest version? I think this shouldn’t be an issue anymore since version 4.5