Thank you for your advice. I have tried the following code with the key from “https://next-gen.materialsproject.org/api”:
from mp_api.client import MPRester
mpr = MPRester("my api_key")
mpr.summary.search(material_ids=["mp-149", "mp-13", "mp-22526"])
But it still doesn’t work. It returns
f"REST query returned with error status code {response.status_code} "
mp_api.core.client.MPRestError: REST query returned with error status code 403 on URL https://api.materialsproject.org/summary/?material_ids=mp-149&material_ids=mp-13&material_ids=mp-22526&all_fields=True&limit=1000 with message:
Response {"error": "You are using deprecated API endpoints. Please read our documentation (https://docs.materialsproject.org) and upgrade to the latest version of the mp-api client (https://pypi.org/project/mp-api/).", "version": "blocked"}
I have upgraded my pymatgen and mp_api using pip install --upgrade pymatgen mp_api
.
Besides, I have also tried MPDataRetrieval
with the following code:
from matminer.data_retrieval.retrieve_MP import MPDataRetrieval
mpdr = MPDataRetrieval(api_key)
query_criteria = {'e_above_hull': {'$lte': 0.08}, 'nelements': {'$gte': 3, '$lte': 4}, 'nsites': {'$lte': 40}}
query_properties = ['material_id', 'formation_energy_per_atom', 'band_gap', 'pretty_formula', 'e_above_hull', 'elements', 'cif', 'spacegroup.number']
dataframe = mpdr.get_dataframe(criteria = query_criteria, properties = query_properties, )
It returns:
raise MPRestError(f"REST query returned with error status code {response.status_code}")
pymatgen.ext.matproj.MPRestError: REST query returned with error status code 403
During handling of the above exception, another exception occurred:
pymatgen.ext.matproj.MPRestError: REST query returned with error status code 403. Content: b'{"valid_response": false, "error": "Invalid request method.", "version": {"db": "2020_09_08", "pymatgen": "2022.0.8", "rest": "2.0"}, "created_at": "2023-10-13T09:42:35.368001"}'
Thank you very much for your help!