How can I resolve proxy when using API from python?

I have created my API key for Materials Project.
However, when I tried to run the following

from mp_api.client import MPRester
with MPRester(“INSERTED_API_KEY”) as mp:
structure = mp.get_structure_by_material_id(“mp-1”)

this is stopped around urllib3.

I would really appreciate any help!

Please post the full error message. Thanks!

Thank you very much @tschaume !

Here is the messages when I interrupted the command.
I would appreciate any help. Thank you:)

File “”, line 22, in
structure = mp.get_structure_by_material_id(“mp-1”)
File “/opt/conda/lib/python3.7/site-packages/mp_api/”, line 205, in get_structure_by_material_id
material_id=material_id, final=final
File “/opt/conda/lib/python3.7/site-packages/mp_api/routes/materials/”, line 37, in get_structure_by_material_id
response = self.get_data_by_id(material_id, fields=[“structure”])
File “/opt/conda/lib/python3.7/site-packages/mp_api/core/”, line 371, in get_data_by_id
criteria=criteria, fields=fields, suburl=document_id, # type: ignore
File “/opt/conda/lib/python3.7/site-packages/mp_api/core/”, line 336, in _query_resource_data
File “/opt/conda/lib/python3.7/site-packages/mp_api/core/”, line 271, in _query_resource
response = self.session.get(url, verify=True, params=criteria)
File “/opt/conda/lib/python3.7/site-packages/requests/”, line 600, in get
return self.request(“GET”, url, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/requests/”, line 587, in request
resp = self.send(prep, **send_kwargs)
File “/opt/conda/lib/python3.7/site-packages/requests/”, line 701, in send
r = adapter.send(request, **kwargs)
File “/opt/conda/lib/python3.7/site-packages/requests/”, line 499, in send
File “/opt/conda/lib/python3.7/site-packages/urllib3/”, line 710, in urlopen
File “/opt/conda/lib/python3.7/site-packages/urllib3/”, line 386, in _make_request
File “/opt/conda/lib/python3.7/site-packages/urllib3/”, line 1040, in _validate_conn
File “/opt/conda/lib/python3.7/site-packages/urllib3/”, line 358, in connect
conn = self._new_conn()
File “/opt/conda/lib/python3.7/site-packages/urllib3/”, line 175, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File “/opt/conda/lib/python3.7/site-packages/urllib3/util/”, line 85, in create_connection

Try upgrading to python 3.9 at least and then also make sure to run the latest versions of pymatgen and mp-api.

1 Like

Hi @tschaume
Thank you for your kind reply.
I will try python 3.9.

Hi @tschaume

The script worked!
Thank you so much for your support! :slight_smile:

1 Like