8000 Accessing CDS API from a WASM/JupyterLite context · Issue #155 · ecmwf/cdsapi · GitHub
[go: up one dir, main page]

Skip to content

Accessing CDS API from a WASM/JupyterLite context #155

Open

Description

@MMesch

What happened?

Hi all,

I'm trying to access ECMWF data from JupyterLite in a WASM context (xpython kernel not pyodide but I don't think that matters). Being able to do so would enable lots of use cases, greatly lowering barriers to access and analyze that data. We are particularly interested in demonstrating how to display that data in JupyterGIS.

I didn't manage to do so for now because

client.retrieve(
    "reanalysis-era5-single-levels",
    {
        "product_type": "reanalysis",
        "variable": "2m_temperature",
        "year": "2023",
        "month": "07",
        "day": "15",
        "time": "12:00",
        "area": [60, -15, 35, 25],  # Europe: N, W, S, E
        "format": "netcdf",
    },
    str(nc_file)
)

on url="https://cds.climate.copernicus.eu/api",

fails with

Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status

It seems that it is mostly due to the CORS policy although I am not fully sure. If this is indeed the case, is it possible to relax that policy and allow cross-origin requests?

What are the steps to reproduce the bug?

Deploy JupyterLite with cdsapi (you can use notebook.link if you don't want to do it yourself, or locally). Then run:

client = cdsapi.Client(
    url="https://cds.climate.copernicus.eu/api",
    key="xxx",
    verify=True
)

nc_file = output_dir / "temperature.nc"
tif_file = output_dir / "temperature.tif"

client.retrieve(
    "reanalysis-era5-single-levels",
    {
        "product_type": "reanalysis",
        "variable": "2m_temperature",
        "year": "2023",
        "month": "07",
        "day": "15",
        "time": "12:00",
        "area": [60, -15, 35, 25],  # Europe: N, W, S, E
        "format": "netcdf",
    },
    str(nc_file)
)

Version

see below

Platform (OS and architecture)

emscription / WASM (xpython)

Relevant log output

"cdsapi-0.7.7-py2.py3-none-any.whl": {
      "url": "https://files.pythonhosted.org/packages/4f/f4/4a65460d5cb6784128019fd707a87993f378db25e796eba01400a0903f62/cdsapi-0.7.7-py2.py3-none-any.whl",
      "hash": {
        "md5": "46183ae020940acdcb7a985b102c8dcb",
        "sha256": "384c1658572d6dc53f4111f6dd46fcdfe6fea54a688af9756d71f6fe9118b66d"
      },
      "name": "cdsapi",
      "size": 12293,
      "version": "0.7.7",
      "registry": "PyPi"
    },
    "ecmwf_datastores_client-0.4.1-py3-none-any.whl": {
      "url": "https://files.pythonhosted.org/packages/a3/cf/7feb3222d770566ca9eaf0bf6922745fadd1ed7ab11832520063a515c240/ecmwf_datastores_client-0.4.1-py3-none-any.whl",
      "hash": {
        "md5": "291634c20afffb2cb303aeb37925e9ca",
        "sha256": "a14515a892889a602ec2c81b15ec81d048932ca05480f12c778136028b6230a3"
      },
      "name": "ecmwf-datastores-client",
      "size": 29094,
      "version": "0.4.1",
      "registry": "PyPi"
    }

Accompanying data

No response

Organisation

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      0