Issue with python code node (Module 'os' is blocked)

Hello Team,

I upgraded n8n from 1.94.x to the latest version 1.98.1 and then today to 1.98.2

A workflow who was currently running without issue is now throwing an error about a python module that I’m not loading.

ModuleNotFoundError: Module 'os' is blocked The module 'os' is removed from the Python standard library in the Pyodide distribution due to browser limitations. See https://pyodide.org/en/stable/usage/loading-packages.html for more details.

The node having the issue is :

The fullstack error

{
  "errorMessage": "ModuleNotFoundError: Module 'os' is blocked\nThe module 'os' is removed from the Python standard library in the Pyodide distribution due to browser limitations.\nSee https://pyodide.org/en/stable/usage/loading-packages.html for more details.\n",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "Extract eml",
    "nodeType": "n8n-nodes-base.code",
    "nodeVersion": 2,
    "n8nVersion": "1.98.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "Error: ModuleNotFoundError: Module 'os' is blocked",
      "The module 'os' is removed from the Python standard library in the Pyodide distribution due to browser limitations.",
      "See https://pyodide.org/en/stable/usage/loading-packages.html for more details.",
      "",
      "    at PythonSandbox.getPrettyError (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_12b981d6b49d407a163f4d5244314033/node_modules/n8n-nodes-base/nodes/Code/PythonSandbox.ts:101:11)",
      "    at PythonSandbox.runCodeInPython (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_12b981d6b49d407a163f4d5244314033/node_modules/n8n-nodes-base/nodes/Code/PythonSandbox.ts:85:15)",
      "    at PythonSandbox.runCodeEachItem (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_12b981d6b49d407a163f4d5244314033/node_modules/n8n-nodes-base/nodes/Code/PythonSandbox.ts:51:27)",
      "    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_12b981d6b49d407a163f4d5244314033/node_modules/n8n-nodes-base/nodes/Code/Code.node.ts:182:14)",
      "    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1187:9)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1536:27",
      "    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2100:11"
    ]
  }
}

I supposed that it was due to a community node I installed, I removed it and removed the ./.n8n/nodes/node_modules/aws-sdk/

Now I’m running out of ideas :slight_smile:

2 Likes

Hey @flo

Using the Code node | n8n Docs.

See above link, you could always try and execution node, which runs shells and calls the py script or do inline py

Samuel

Hello @King_Samuel_David,
Thank you for the link.

But I’m not sure to understand how it can solve my issue.

I feel like you assume that the code I’m using should use python itself when I’m seeing that the python code is looking for a module that I’m not using.

Did I get something wrong ?

Regards,

This was mentioned here.

Hey @flo

So as mentioned it seems to be a problem in newer version, you can try 1.97.1 which is confirmed working via the post from jabbson.

I was talking about using this node instead

This allow more flexabity I find, but down to preferance as alittle more work needed, obviously make sure python is actually installed etc.

Hope that helps,

Samuel
Samuel

1 Like

Hey @flo , maybe this is too late, but I had the same issue. The answer to your question about why you’re getting this despite not importing os is that you’re using a package (probably email) that itself has os as a dependency. The same bug is preventing me from using pandas or numpy. Hoping for a fix soon :slight_smile:

Hello @woodsman
Yes, I came to the same statement and downgraded to 1.97.1 until a fix is released.

I ran into the same issue when trying to use CairoSVG and Pillow libraries. The problem with the node Code seems to be that it forces the system to interpret the Python code in Pyodide instead of the operating system. So what I did as a workarround was to save my script as a .py file, copy it into my Docker container and execute the comand via Execute node, as I would do using the terminal.
Seems to me that this approach is more flexible, altho a little bit more work is necessary.

1 Like