Hi everyone,
I’m new to using the mp-api
Python client and recently encountered an issue while running example code to query materials summary data from the Materials Project.
Here’s the exact code I used (adapted from the official documentation):
with MPRester(API_key) as mpr:
docs = mpr.materials.summary.search(
elements=["Si", "O"],
band_gap=(0.5, 1.0)
)
print(docs)
And the error traceback is as follows:
File ~\.conda\envs\materialproject\Lib\site-packages\mp_api\client\core\client.py:1075, in BaseRester._generate_returned_model(self, doc)
1067 unset_fields = [field for field in doc.model_fields if field not in set_fields]
1069 data_model = create_model( # type: ignore
1070 "MPDataDoc",
1071 fields_not_requested=(list[str], unset_fields),
1072 __base__=self.document_model, # type: ignore
1073 )
-> 1075 data_model.model_fields = {
1076 **{
1077 name: description
1078 for name, description in data_model.model_fields.items()
1079 if name in set_fields
1080 },
1081 "fields_not_requested": data_model.model_fields["fields_not_requested"],
1082 }
1084 def new_repr(self) -> str:
1085 extra = ",\n".join(
1086 f"\033[1m{n}\033[0;0m={getattr(self, n)!r}"
1087 for n in data_model.model_fields
1088 )
AttributeError: property 'model_fields' of 'ModelMetaclass' object has no setter
I am running this code on Python 3.12.7
Despite these attempts, the issue persists. As a new user of mp-api
, I’m unsure if this is due to a version incompatibility, a bug, or a misunderstanding of the API usage.
Has anyone encountered similar issues or could provide advice on how to fix this? Any help would be greatly appreciated!
Thank you in advance for your time and support!