Cloud version 2.3.6: Python (Native): How to use Python standard libraries?

Describe the problem/error/question

The Python (Native) node ion n8n cloud version 2.3.6 can’t import Python standard libraries like these ones:

import email
import json
from io import BytesIO

What is the error message (if any)?

Line 1: Import of standard library module 'email' is disallowed. Allowed stdlib modules: none
Line 2: Import of standard library module 'json' is disallowed. Allowed stdlib modules: none
Line 3: Import of standard library module 'io' is disallowed. Allowed stdlib modules: none

Please share your workflow

Share the output returned by the last node

{
“errorMessage”: “Security violations detected”,
“errorDescription”: “Line 1: Import of standard library module ‘email’ is disallowed. Allowed stdlib modules: none\nLine 2: Import of standard library module ‘json’ is disallowed. Allowed stdlib modules: none\nLine 3: Import of standard library module ‘io’ is disallowed. Allowed stdlib modules: none”,
“errorDetails”: {},
“n8nDetails”: {
“n8nVersion”: “2.1.5 (Cloud)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“Error: Security violations detected”,
" at throwExecutionError (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/Code/throw-execution-error.ts:11:9)“,
" at PythonTaskRunnerSandbox.runUsingIncomingItems (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/Code/PythonTaskRunnerSandbox.ts:57:30)”,
" at processTicksAndRejections (node:internal/process/task_queues:105:5)“,
" at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/Code/Code.node.ts:171:12)”,
" at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1045:8)“,
" at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1226:11)”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1662:27",
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_ec37920eb95917b28efaa783206b20f3/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2274:11"
]
}
}

Information on your n8n setup

  • n8n version: 2.3.6 (Cloud)
  • Database (default: SQLite): none
  • n8n EXECUTIONS_PROCESS setting (default: own, main): none
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: none
2 Likes

The issue is the Python (Native) node in n8n Cloud version 2.3.6 disallows importing standard library modules like `email`, `json`, and `io`. This is likely due to security restrictions within the cloud environment.

You might want to consider using the Code node with JavaScript, as suggested in the search results, since it offers more flexibility with its included libraries. Alternatively, you could explore other nodes that offer similar functionality without needing to import these specific libraries.

@achamm Sorry for being rude, but your reply was so fast and generic that I have to ask: Is this an AI generated answer?!

Being more precise: The n8n error message states that the Python modules are not allowed, but the documentation does not say that there are any restrictions to the standard libraries. Only external libraries are restricted.

Furthermore I can’t use Javascript as I’m a Python developer and don’t know anything about Javascript, therefore I won’t use AI generated code. Also Python is already flexible due to it’s integrated (standard) modules, no need to use Javascript.

Alternatively, you could explore other nodes that offer similar functionality without needing to import these specific libraries.

…obvious answer. Due to the fact that I have not found another node/workflow I wrote a simple Python script.

Once again I’m sorry for being rude, but I can’t remember when I lastly got such an answer - except from ChatGPT.

I forgot to mention that I also created an issuew on Github as I’m not sure if this is a bug or not: Code in Python (Native): `Import of standard library module 'email' is disallowed. Allowed stdlib modules: none` · Issue #24520 · n8n-io/n8n · GitHub

Hi @TheRealBecks, welcome!

as you already saw:

Allowed stdlib modules: none

so, It’s not possible in n8n cloud atm,

You could try using something like AWS Lambda or a similar, depending on what you’re trying to achieve..

@mohamed3nan Yeah, it’s not implemented as can be seen in this new comment.

1 Like

It’s not ai generated, but I’ve been automating my responses more by doing it through code, so I get alerted when people post. I did a bit of post automation with AI but it wasnt properly helping people out so i need to fix it before I test it again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.