pyodide: Failed to find a valid digest in the 'integrity' attribute for resource...

🐛 Bug

The error message shown on the Chrome browser console is:

Failed to find a valid digest in the 'integrity' attribute for resource 'http://localhost:5173/node_modules/pyodide/attrs-23.2.0-py3-none-any.whl' with computed SHA-256 integrity '7OD6JEKxDa+4OZw1g2X3/N2eVn+IP7ZQYj6WpJVx0rs='. The resource has been blocked.

I have a Python playground that allows users to install packages on the fly.

image

Here is the JavaScript codes:

const installPackage = async (newPackageName) => {
  if (!pyodide) {
    alert(`\`pyodide\` is \`null\``)
    await initializePyodide();
  };
  try {
    const packagesData = await pyodide.value.loadPackage(newPackageName); // PackageData[]
    pyodide.value = pyodide.value
    alert(`successfully installed \`${newPackageName}\``)
    return newPackageName;
  } catch (err) {
    alert(`[ERROR] failed to load \`${newPackageName}\`; \`error\` = ${err}`)
    return null;
  }
}

const addPackage = async () => {
  const newPackageName = newPackage.value.trim();
  if (newPackageName !== '' && !packages.value.includes(newPackageName)) {
    if (newPackageName === await installPackage(newPackageName)) {
      packages.value.push(newPackageName); // Add the new package to the list
    } else {
      alert(`[ERROR] failed to install \`${newPackageName}\``);
    }
    newPackage.value = ''; // Clear the input field
  } else {
    // Optionally handle invalid input or duplicate package
    alert('Invalid or duplicate package.');
  }
}

The funny thing is when I try running the codes after the pyodide has loaded the packages, the console tells me the package is not loaded because it fails the integrity check.

How can I solve this?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I also encountered the same errors with pyodide v0.26.2 and got some hypothesis about the problem.

According to @jymchng 's error message:

ReadError: /tmp/tmp17sn0189cachetools-5.3.3-py3-none-any.whl is not a zip file

it looks like the wheel file has a strange filepath.

Probably there is a path manipulation bug in the extraction of the wheel file in _package_loader.py in pyodide.

maybe around here https://github.com/pyodide/pyodide/blob/61f184a16464b94f645f864530b4fea31eed37fb/src/py/pyodide/_package_loader.py#L212

As for the checkIntegrity option, I think that following problems are happening:

  • In the case of checkIntegrity: false: the loader tries to extract the non-existent file and fails.
  • In the case of checkIntegrity: true: the loader checks the integrity of the non-existent file and considers it is invalid.