Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable requests.Session.trust_env on default #648

Merged
merged 1 commit into from Jul 29, 2022

Conversation

ksauzz
Copy link
Contributor

@ksauzz ksauzz commented Jul 28, 2022

Summary

Disable Enable requests.Session.trust_env on default to use HTTP_PROXY/HTTPS_PROXY env and avoid unexpected behavior.
Please let me know if any specific reason exists to need requests.Session.trust_env=true requests.Session.trust_env=Falseon default.

see: requests.Session.trust_env

Background

We have an application running behind a HTTP proxy using HTTP_PROXY and HTTPS_PROXY env because of security purpose. We tried to use mp-api, then we observed the client use the proxy for contribs-api.materialsproject.org endpoint, but doesn't use the proxy for api.materialsproject.org. After the investigation, we found requests.Session.trus_env=False ignore the environment variables of proxy servers.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • disable requests.Session.trus_env on default
  • I have run the tests locally and they passed. I have run the tests.: It seems 1 failed test exists on main branch.
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR.: This is very small fix, and doesn't break existing tests.

@munrojm
Copy link
Member

munrojm commented Jul 28, 2022

Hi @ksauzz! For api.materialsproject.org, we definitely don't need it set to True. I will let @tschaume comment on the MPContribs side before I merge.

@tschaume
Copy link
Member

@ksauzz Just to confirm, this is working as expected for the MPContribs client, right?

@ksauzz
Copy link
Contributor Author

ksauzz commented Jul 28, 2022

@tschaume Yes, it works as expected. In my understanding this session object isn't shared with mpcontribs-client since mpcontribs-client use HTTP(S)_PROXY env without this change. Additionally according to the code it looks mpcontribs-client creates another session object here. FuturesSession's constructor can take session keyword arg, but nothing is here.

My pytest's result is the following:

run tests w/o a proxy
MP_API_KEY=<API KEY> .venv/bin/pytest
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/kazuhiro/work/mp-api, configfile: setup.cfg
plugins: asyncio-0.18.3, mock-3.7.0, anyio-3.6.1, cov-3.0.0
asyncio: mode=legacy
collected 90 items

tests/test_bonds.py .                                                    [  1%]
tests/test_charge_density.py .F.                                         [  4%]
tests/test_client.py ...............................                     [ 38%]
tests/test_core_client.py x..xx.                                         [ 45%]
tests/test_dielectric.py .                                               [ 46%]
tests/test_elasticity.py X                                               [ 47%]
tests/test_electrodes.py .                                               [ 48%]
tests/test_electronic_structure.py ...                                   [ 52%]
tests/test_eos.py .                                                      [ 53%]
tests/test_grain_boundary.py .                                           [ 54%]
tests/test_magnetism.py .                                                [ 55%]
tests/test_materials.py .                                                [ 56%]
tests/test_molecules.py .                                                [ 57%]
tests/test_mprester.py .......s.....ss.x.                                [ 77%]
tests/test_oxidation_states.py .                                         [ 78%]
tests/test_piezo.py .                                                    [ 80%]
tests/test_provenance.py .                                               [ 81%]
tests/test_robocrys.py .                                                 [ 82%]
tests/test_substrates.py .                                               [ 83%]
tests/test_summary.py s                                                  [ 84%]
tests/test_surface_properties.py .                                       [ 85%]
tests/test_synthesis.py ...xx...                                         [ 94%]
tests/test_tasks.py ..                                                   [ 96%]
tests/test_thermo.py .X                                                  [ 98%]
tests/test_xas.py .                                                      [100%]

=================================== FAILURES ===================================
__________________________ test_download_for_task_ids __________________________

tmpdir = local('/tmp/pytest-of-kazuhiro/pytest-6/test_download_for_task_ids0')
rester = <ChargeDensityRester https://api.materialsproject.org/charge_density/>

    def test_download_for_task_ids(tmpdir, rester):
    
>       n = rester.download_for_task_ids(
            task_ids=["mp-655585", "mp-1057373", "mp-1059589", "mp-1440634", "mp-1791788"],
            path=tmpdir,
        )

tests/test_charge_density.py:90: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/mp_api/routes/charge_density.py:47: in download_for_task_ids
    chgcar_summary_docs = self.search(task_ids=task_ids)
src/mp_api/routes/charge_density.py:70: in search
    return super()._search(
src/mp_api/core/client.py:832: in _search
    return self._get_all_documents(
src/mp_api/core/client.py:881: in _get_all_documents
    results = self._query_resource(
src/mp_api/core/client.py:295: in _query_resource
    data = self._submit_requests(
src/mp_api/core/client.py:390: in _submit_requests
    initial_data_tuples = self._multi_thread(use_document_model, initial_params_list)
src/mp_api/core/client.py:591: in _multi_thread
    data, subtotal = future.result()
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/_base.py:437: in result
    return self.__get_result()
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/_base.py:389: in __get_result
    raise self._exception
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/thread.py:57: in run
    result = self.fn(*self.args, **self.kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ChargeDensityRester https://api.materialsproject.org/charge_density/>
url = 'https://api.materialsproject.org/charge_density/', verify = True
params = {'_fields': 'last_updated,task_id,fs_id', '_limit': 10, 'task_ids': ['mp-655585', 'mp-1057373', 'mp-1059589', 'mp-1440634', 'mp-1791788']}
use_document_model = True, timeout = None

    def _submit_request_and_process(
        self,
        url: str,
        verify: bool,
        params: dict,
        use_document_model: bool,
        timeout: int = None,
    ) -> Tuple[Dict, int]:
        """
        Submits GET request and handles the response.
    
        Arguments:
            url: URL to send request to
            verify: whether to verify the server's TLS certificate
            params: dictionary of parameters to send in the request
            use_document_model: if None, will defer to the self.use_document_model attribute
            timeout: Time in seconds to wait until a request timeout error is thrown
    
        Returns:
            Tuple with data and total number of docs in matching the query in the database.
        """
        try:
            response = self.session.get(url=url, verify=verify, params=params, timeout=timeout)
        except requests.exceptions.ConnectTimeout:
            raise MPRestError(f"REST query timed out on URL {url}. Try again with a smaller request.")
    
        if response.status_code == 200:
    
            if self.monty_decode:
                data = json.loads(response.text, cls=MontyDecoder)
            else:
                data = json.loads(response.text)
    
            # other sub-urls may use different document models
            # the client does not handle this in a particularly smart way currently
            if self.document_model and use_document_model:
                raw_doc_list = [self.document_model.parse_obj(d) for d in data["data"]]  # type: ignore
    
                # Temporarily removed until user-testing completed
                # data["data"] = self._generate_returned_model(raw_doc_list)
    
                data["data"] = raw_doc_list
    
            meta_total_doc_num = data.get("meta", {}).get("total_doc", 1)
    
            return data, meta_total_doc_num
    
        else:
            try:
                data = json.loads(response.text)["detail"]
            except (JSONDecodeError, KeyError):
                data = "Response {}".format(response.text)
            if isinstance(data, str):
                message = data
            else:
                try:
                    message = ", ".join("{} - {}".format(entry["loc"][1], entry["msg"]) for entry in data)
                except (KeyError, IndexError):
                    message = str(data)
    
>           raise MPRestError(
                f"REST query returned with error status code {response.status_code} "
                f"on URL {response.url} with message:\n{message}"
            )
E           mp_api.core.client.MPRestError: REST query returned with error status code 403 on URL https://api.materialsproject.org/charge_density/?task_ids=mp-655585&task_ids=mp-1057373&task_ids=mp-1059589&task_ids=mp-1440634&task_ids=mp-1791788&_limit=10&_fields=last_updated%2Ctask_id%2Cfs_id with message:
E           Response {
E             "message":"You cannot consume this service"
E           }

src/mp_api/core/client.py:673: MPRestError
=============================== warnings summary ===============================
.venv/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191
  /home/kazuhiro/work/mp-api/.venv/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

.venv/lib/python3.8/site-packages/matminer/featurizers/site/fingerprint.py:32
.venv/lib/python3.8/site-packages/matminer/featurizers/site/fingerprint.py:34
  
  safe_load will be removed, use
  
    yaml=YAML(typ='safe', pure=True)
    yaml.load(...)
  
  instead

.venv/lib/python3.8/site-packages/ruamel/yaml/main.py:1118
.venv/lib/python3.8/site-packages/ruamel/yaml/main.py:1118
  
  load will be removed, use
  
    yaml=YAML(typ='unsafe', pure=True)
    yaml.load(...)
  
  instead

.venv/lib/python3.8/site-packages/pymatgen/analysis/alloys/core.py:28
  Please use `HalfspaceIntersection` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated.

src/mp_api/matproj.py:7
  The MPRester class has been moved. You can now use `from mp_api import MPRester`.

tests/test_core_client.py::test_get_document_no_doc
tests/test_mprester.py::TestMPRester::test_get_materials_id_from_task_id
  This method is deprecated, please use get_material_id_from_task_id.

tests/test_core_client.py::test_get_document_no_doc
  No material found containing task mp-1a. Please report it if you suspect a task has gone missing.

tests/test_grain_boundary.py::test_client
  Not all sites have property grain_label. Missing values are set to None.

tests/test_mprester.py::TestMPRester::test_get_materials_ids_references
  This method is deprecated, please use get_material_id_references instead.

tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
  This method is deprecated, please use get_material_ids.

tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
  Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================= slowest 30 durations =============================
28.81s call     tests/test_materials.py::test_client
13.87s call     tests/test_substrates.py::test_client
10.46s call     tests/test_synthesis.py::test_client
10.04s call     tests/test_synthesis.py::test_filters_keywords
7.86s call     tests/test_electronic_structure.py::test_es_client
7.38s call     tests/test_mprester.py::TestMPRester::test_get_entries_in_chemsys
6.62s call     tests/test_client.py::test_generic_get_methods[rester7]
6.29s call     tests/test_client.py::test_generic_get_methods[rester29]
5.38s call     tests/test_client.py::test_generic_get_methods[rester25]
4.86s call     tests/test_electrodes.py::test_client
4.52s call     tests/test_xas.py::test_client
4.49s call     tests/test_mprester.py::TestMPRester::test_get_entries
4.44s call     tests/test_client.py::test_generic_get_methods[rester5]
4.08s call     tests/test_dielectric.py::test_client
3.94s call     tests/test_mprester.py::TestMPRester::test_get_bandstructure_by_material_id
3.70s call     tests/test_synthesis.py::test_filters_atmosphere
2.89s call     tests/test_client.py::test_generic_get_methods[rester11]
2.66s call     tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
2.54s call     tests/test_electronic_structure.py::test_bs_client
2.44s call     tests/test_thermo.py::test_client
2.44s call     tests/test_elasticity.py::test_client
2.38s call     tests/test_grain_boundary.py::test_client
2.26s call     tests/test_surface_properties.py::test_client
2.18s call     tests/test_magnetism.py::test_client
2.13s call     tests/test_robocrys.py::test_client
1.91s call     tests/test_mprester.py::TestMPRester::test_get_structure_by_material_id
1.88s call     tests/test_oxidation_states.py::test_client
1.85s call     tests/test_mprester.py::TestMPRester::test_get_structures
1.83s call     tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
1.64s call     tests/test_synthesis.py::test_filters_synthesis_type
=========================== short test summary info ============================
FAILED tests/test_charge_density.py::test_download_for_task_ids - mp_api.core...
= 1 failed, 77 passed, 4 skipped, 6 xfailed, 2 xpassed, 16 warnings in 193.18s (0:03:13) =

run tests w/ a proxy
MP_API_KEY=<API KEY> HTTPS_PROXY=http://localhost:3128 .venv/bin/pytest
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/kazuhiro/work/mp-api, configfile: setup.cfg
plugins: asyncio-0.18.3, mock-3.7.0, anyio-3.6.1, cov-3.0.0
asyncio: mode=legacy
collected 90 items

tests/test_bonds.py .                                                    [  1%]
tests/test_charge_density.py .F.                                         [  4%]
tests/test_client.py ...............................                     [ 38%]
tests/test_core_client.py x..xx.                                         [ 45%]
tests/test_dielectric.py .                                               [ 46%]
tests/test_elasticity.py X                                               [ 47%]
tests/test_electrodes.py .                                               [ 48%]
tests/test_electronic_structure.py ...                                   [ 52%]
tests/test_eos.py .                                                      [ 53%]
tests/test_grain_boundary.py .                                           [ 54%]
tests/test_magnetism.py .                                                [ 55%]
tests/test_materials.py .                                                [ 56%]
tests/test_molecules.py .                                                [ 57%]
tests/test_mprester.py .......s.....ss.x.                                [ 77%]
tests/test_oxidation_states.py .                                         [ 78%]
tests/test_piezo.py .                                                    [ 80%]
tests/test_provenance.py .                                               [ 81%]
tests/test_robocrys.py .                                                 [ 82%]
tests/test_substrates.py .                                               [ 83%]
tests/test_summary.py s                                                  [ 84%]
tests/test_surface_properties.py .                                       [ 85%]
tests/test_synthesis.py ...xx...                                         [ 94%]
tests/test_tasks.py ..                                                   [ 96%]
tests/test_thermo.py .X                                                  [ 98%]
tests/test_xas.py .                                                      [100%]

=================================== FAILURES ===================================
__________________________ test_download_for_task_ids __________________________

tmpdir = local('/tmp/pytest-of-kazuhiro/pytest-7/test_download_for_task_ids0')
rester = <ChargeDensityRester https://api.materialsproject.org/charge_density/>

    def test_download_for_task_ids(tmpdir, rester):
    
>       n = rester.download_for_task_ids(
            task_ids=["mp-655585", "mp-1057373", "mp-1059589", "mp-1440634", "mp-1791788"],
            path=tmpdir,
        )

tests/test_charge_density.py:90: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/mp_api/routes/charge_density.py:47: in download_for_task_ids
    chgcar_summary_docs = self.search(task_ids=task_ids)
src/mp_api/routes/charge_density.py:70: in search
    return super()._search(
src/mp_api/core/client.py:832: in _search
    return self._get_all_documents(
src/mp_api/core/client.py:881: in _get_all_documents
    results = self._query_resource(
src/mp_api/core/client.py:295: in _query_resource
    data = self._submit_requests(
src/mp_api/core/client.py:390: in _submit_requests
    initial_data_tuples = self._multi_thread(use_document_model, initial_params_list)
src/mp_api/core/client.py:591: in _multi_thread
    data, subtotal = future.result()
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/_base.py:437: in result
    return self.__get_result()
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/_base.py:389: in __get_result
    raise self._exception
../../.pyenv/versions/3.8.10/lib/python3.8/concurrent/futures/thread.py:57: in run
    result = self.fn(*self.args, **self.kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ChargeDensityRester https://api.materialsproject.org/charge_density/>
url = 'https://api.materialsproject.org/charge_density/', verify = True
params = {'_fields': 'last_updated,task_id,fs_id', '_limit': 10, 'task_ids': ['mp-655585', 'mp-1057373', 'mp-1059589', 'mp-1440634', 'mp-1791788']}
use_document_model = True, timeout = None

    def _submit_request_and_process(
        self,
        url: str,
        verify: bool,
        params: dict,
        use_document_model: bool,
        timeout: int = None,
    ) -> Tuple[Dict, int]:
        """
        Submits GET request and handles the response.
    
        Arguments:
            url: URL to send request to
            verify: whether to verify the server's TLS certificate
            params: dictionary of parameters to send in the request
            use_document_model: if None, will defer to the self.use_document_model attribute
            timeout: Time in seconds to wait until a request timeout error is thrown
    
        Returns:
            Tuple with data and total number of docs in matching the query in the database.
        """
        try:
            response = self.session.get(url=url, verify=verify, params=params, timeout=timeout)
        except requests.exceptions.ConnectTimeout:
            raise MPRestError(f"REST query timed out on URL {url}. Try again with a smaller request.")
    
        if response.status_code == 200:
    
            if self.monty_decode:
                data = json.loads(response.text, cls=MontyDecoder)
            else:
                data = json.loads(response.text)
    
            # other sub-urls may use different document models
            # the client does not handle this in a particularly smart way currently
            if self.document_model and use_document_model:
                raw_doc_list = [self.document_model.parse_obj(d) for d in data["data"]]  # type: ignore
    
                # Temporarily removed until user-testing completed
                # data["data"] = self._generate_returned_model(raw_doc_list)
    
                data["data"] = raw_doc_list
    
            meta_total_doc_num = data.get("meta", {}).get("total_doc", 1)
    
            return data, meta_total_doc_num
    
        else:
            try:
                data = json.loads(response.text)["detail"]
            except (JSONDecodeError, KeyError):
                data = "Response {}".format(response.text)
            if isinstance(data, str):
                message = data
            else:
                try:
                    message = ", ".join("{} - {}".format(entry["loc"][1], entry["msg"]) for entry in data)
                except (KeyError, IndexError):
                    message = str(data)
    
>           raise MPRestError(
                f"REST query returned with error status code {response.status_code} "
                f"on URL {response.url} with message:\n{message}"
            )
E           mp_api.core.client.MPRestError: REST query returned with error status code 403 on URL https://api.materialsproject.org/charge_density/?task_ids=mp-655585&task_ids=mp-1057373&task_ids=mp-1059589&task_ids=mp-1440634&task_ids=mp-1791788&_limit=10&_fields=last_updated%2Ctask_id%2Cfs_id with message:
E           Response {
E             "message":"You cannot consume this service"
E           }

src/mp_api/core/client.py:673: MPRestError
=============================== warnings summary ===============================
.venv/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191
  /home/kazuhiro/work/mp-api/.venv/lib/python3.8/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

.venv/lib/python3.8/site-packages/matminer/featurizers/site/fingerprint.py:32
.venv/lib/python3.8/site-packages/matminer/featurizers/site/fingerprint.py:34
  
  safe_load will be removed, use
  
    yaml=YAML(typ='safe', pure=True)
    yaml.load(...)
  
  instead

.venv/lib/python3.8/site-packages/ruamel/yaml/main.py:1118
.venv/lib/python3.8/site-packages/ruamel/yaml/main.py:1118
  
  load will be removed, use
  
    yaml=YAML(typ='unsafe', pure=True)
    yaml.load(...)
  
  instead

.venv/lib/python3.8/site-packages/pymatgen/analysis/alloys/core.py:28
  Please use `HalfspaceIntersection` from the `scipy.spatial` namespace, the `scipy.spatial.qhull` namespace is deprecated.

src/mp_api/matproj.py:7
  The MPRester class has been moved. You can now use `from mp_api import MPRester`.

tests/test_core_client.py::test_get_document_no_doc
tests/test_mprester.py::TestMPRester::test_get_materials_id_from_task_id
  This method is deprecated, please use get_material_id_from_task_id.

tests/test_core_client.py::test_get_document_no_doc
  No material found containing task mp-1a. Please report it if you suspect a task has gone missing.

tests/test_grain_boundary.py::test_client
  Not all sites have property grain_label. Missing values are set to None.

tests/test_mprester.py::TestMPRester::test_get_materials_ids_references
  This method is deprecated, please use get_material_id_references instead.

tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
  This method is deprecated, please use get_material_ids.

tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
  Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================= slowest 30 durations =============================
31.26s call     tests/test_materials.py::test_client
13.20s call     tests/test_substrates.py::test_client
10.38s call     tests/test_synthesis.py::test_client
9.41s call     tests/test_synthesis.py::test_filters_keywords
8.13s call     tests/test_electrodes.py::test_client
7.68s call     tests/test_mprester.py::TestMPRester::test_get_entries_in_chemsys
6.45s call     tests/test_client.py::test_generic_get_methods[rester7]
6.39s call     tests/test_xas.py::test_client
6.13s call     tests/test_client.py::test_generic_get_methods[rester29]
5.67s call     tests/test_electronic_structure.py::test_es_client
4.86s call     tests/test_mprester.py::TestMPRester::test_get_entries
4.33s call     tests/test_client.py::test_generic_get_methods[rester5]
4.28s call     tests/test_mprester.py::TestMPRester::test_get_materials_ids_doc
4.18s call     tests/test_mprester.py::TestMPRester::test_get_bandstructure_by_material_id
4.02s call     tests/test_oxidation_states.py::test_client
3.99s call     tests/test_synthesis.py::test_filters_temperature_range
3.59s call     tests/test_mprester.py::TestMPRester::test_get_phonon_data_by_material_id
2.99s call     tests/test_client.py::test_generic_get_methods[rester11]
2.97s call     tests/test_surface_properties.py::test_client
2.70s call     tests/test_client.py::test_generic_get_methods[rester25]
2.56s call     tests/test_elasticity.py::test_client
2.53s call     tests/test_electronic_structure.py::test_bs_client
2.53s call     tests/test_grain_boundary.py::test_client
2.45s call     tests/test_thermo.py::test_client
2.41s call     tests/test_robocrys.py::test_client
2.37s call     tests/test_eos.py::test_client
1.89s call     tests/test_mprester.py::TestMPRester::test_get_structure_by_material_id
1.78s call     tests/test_mprester.py::TestMPRester::test_get_dos_by_id
1.68s call     tests/test_magnetism.py::test_client
1.65s call     tests/test_synthesis.py::test_filters_mixing_media
=========================== short test summary info ============================
FAILED tests/test_charge_density.py::test_download_for_task_ids - mp_api.core...
= 1 failed, 77 passed, 4 skipped, 6 xfailed, 2 xpassed, 16 warnings in 200.60s (0:03:20) =

how to run squid as a http proxy for materialsproject.org

cat<<EOS> squid.conf
acl mp dstdomain contribs-api.materialsproject.org
acl mp dstdomain api.materialsproject.org
http_access allow mp
http_port 3128
EOS
docker run -p 3128:3128 --rm -it -v $(pwd)/squid.conf:/etc/squid/squid.conf sameersbn/squid:latest

tail access logs

docker exec -it $(docker ps | grep sameersbn/squid | awk '{print $1}') tail -f /var/log/squid/access.log

@munrojm munrojm added the release:patch Patch release label Jul 29, 2022
@munrojm munrojm merged commit ef951a2 into materialsproject:main Jul 29, 2022
@ksauzz ksauzz deleted the fix/enable-trust-env branch July 29, 2022 01:08
@ksauzz
Copy link
Contributor Author

ksauzz commented Jul 29, 2022

Thank you all!!

BTW, I'm sorry for my wrong the PR's title and description. I wrote true and false the other way round.
The original code set requests.Session.trust_env=False explicitly. This means the client ignores HTTP(S)_PROXY.
This PR removes the line to use the default value, that is requests.Session.trust_env=True to respect HTTP(S)_PROXY.

I'm going to fix them.

@ksauzz ksauzz changed the title disable requests.Session.trus_env on default enable requests.Session.trust_env on default Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:patch Patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants