Skip to content

[Bug]: MPRester fails due to 403 on /heartbeat endpoint (Cloudflare bot detection) #1055

@lan496

Description

@lan496

Description

When using mp_api.client.MPRester, I encounter an error during initialization related to accessing the /heartbeat endpoint.

/usr/local/lib/python3.13/site-packages/mp_api/client/mprester.py:229: in __init__
    emmet_version = MPRester.get_emmet_version(self.endpoint)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/local/lib/python3.13/site-packages/mp_api/client/mprester.py:494: in get_emmet_version
    response = get(url=endpoint + "heartbeat").json()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Observed behavior

From reading the code, MPRester appears to access https://api.materialsproject.org/heartbeat without an API key in order to retrieve version information (database and emmet versions). However, this request consistently returns a 403 Forbidden, likely due to Cloudflare’s bot detection. For example: curl -i https://api.materialsproject.org/heartbeat also returns a 403 status.

Suggestion

I understand the operational challenges of running a large API service like the Materials Project. That said, it would be very helpful if the client could support a fallback behavior, for example:

  • Gracefully skipping get_database_version / get_emmet_version when /heartbeat is unreachable
  • Catching and ignoring 403 (or network) errors for version checks
  • Optionally allowing users to disable version checks via a flag or environment variable

Related issue

This may be related to the following issue: #817

Version

mp-api 0.45.15

Which OS?

  • MacOS
  • Windows
  • Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions