MPRestError status code 403

My research group is using the materials project for accessing structures for a project and have had a working piece of code for several months that is suddenly having a new error.

We have been performing the query below without issue until recently.

with MPRester(api_key=api_key) as mpr:
docs = mpr.query(
criteria=criteria,
properties=[“material_id”, “structure”]
)

using
from pymatgen.ext.matproj import MPRester

This is the new error we are seeing.

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-06-21T08:58:30.680393”}’

Does anyone have any insight into this issue? Let me know if providing more information would be useful.

Matt

I think you just need to update the versions of the mp-api, pymatgen, etc. packages. If this is the issue I’m thinking it is, then it was caused by a recent version change.

Hi Matt, I’m having the same error. Please see my other thread. I imagine it is something on the Materials Project end.

Thanks for pointing this out Wenhao, yes this appears to be an issue with the legacy API and using the old mpr.query() now

Thanks for reporting this @matthewkuner. Let’s continue in the thread that @Wenhao_Sun referenced.

@Matthew_Greenberg

I faced the same issue, here is how I resolved it.

When you use “pymatgen.ext.matproj import MPRester”, you need to use legacy API. You can read more about it here. Materials Project - API

So you can use this code to print structure info of any material.

from pymatgen.ext.matproj import MPRester

with MPRester(“YOUR LEGACY API”) as mpr:
structures = mpr.get_structures(“PbS”)

print (structures)