I have been able to do calculations in HPC using data available from the legacy version of materialsproject using pymatgen. However after switching into the new version where I am using the new API key from mp-api, I am getting connection error as;

“pymatgen.ext.matproj.MPRestError: HTTPSConnectionPool(host=‘’, port=443): Max retries exceeded with url: /rest/v2/api_check (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x2ac42bc03970>: Failed to establish a new connection: [Errno 101] Network is unreachable’))”

Could anybody help to resolve this issue? Thanks in advance

Hi Akil,

Please consult this page of the docs:

As of right now, you should import from pymatgen for the legacy API and legacy API key format, and from mp_api from the new API and new API key format.

A compatibility layer will be added to pymatgen in the near future.



Dear Matt,
Thanks for your reply. However, the problem I am facing is not regarding which version. I have been using the new API by from mp_api.client import MPRester after mp-api installation itself and not from the pymatgen . But I am getting error as;
“mp_api.client.core.client.MPRestError: REST query returned with error status code 404 on URL with message:”
followed by a long section starting as '!DOCTYPE html>

Materials Project :: 404 "

I am attaching my code as well for your reference here;

import os
import warnings
from mp_api.client import MPRester
#ASE terms
from ase import Atoms
from import read,write, Trajectory
from ase.optimize import BFGS as BFGS
from ase.calculators.aims import Aims
#Pymatgen terms
from pymatgen.core import Structure,Element,Molecule
from pymatgen.analysis.pourbaix_diagram import PourbaixDiagram, PourbaixPlotter, PourbaixEntry
from import AseAtomsAdaptor
import matplotlib.pyplot as plt
def get_ase_structure(material_id):
mpr= MPRester(API_KEY)
return ase_structure
def fhi_aims_calculator(kgrid):
aims_calc = Aims(
relativistic=“atomic_zora scalar”,
relax_geometry= “bfgs 5e-3”,
run_command=“srun aims.210716_3.scalapack.mpi.x > aims.out”)
return aims_calc
print('Energy: ',tio2_energy)

It seems like there is an error in connecting to pymatgen. Could you pls have a look

The URL in your error message seems to combine the legacy REST URL with the format for the materials endpoint in the new API. Do you have MP_API_ENDPOINT set to the legacy URL in your environment by any chance? Also, which mp_api and pymatgen versions are you using? Does the same error get triggered when you try this minimal example (make sure to run it in a separate script or new notebook):

from mp_api.client import MPRester

# use API key from
with MPRester("your-api-key") as mpr:

I encountered the same error. I ran the program through the anaconda environment and suddenly encountered this error during a certain run. After investigation, it was found that there was a conflict with the dependent environment. Simply build a new virtual environment and input it again:
pip install mp-api
Can solve the problem

Thread closed due to inactivity, please open a new thread to address related issues.