n8n Python代码节点编写
为n8n Code节点编写可运行的Python,正确读取输入、处理Webhook与批量数据,并规避库限制和返回格式错误。
功能与用途
输入你的n8n工作流需求、节点模式、示例数据或报错信息,即可获得适用于Python Code节点的代码、数据访问方式和排错建议。内容覆盖批量处理、逐项处理、Webhook body读取、正则与统计等常见任务,并明确外部库不可用时的替代方案。使用前需确认代码运行在n8n Code节点的Python模式中;涉及HTTP请求、复杂日期处理或多数常规转换时,通常应优先考虑JavaScript或其他专用节点。
适用场景
- Webhook数据提取:从n8n Webhook的body中安全读取姓名、邮箱或订单字段,并生成标准输出。
- 批量数据转换:使用_input.all()过滤、清洗、补字段或聚合多条输入数据。
- 正则与统计处理:用re、statistics等标准库完成文本提取、金额汇总、均值和中位数计算。
- 节点报错排查:定位外部库导入、KeyError、缺少return或json返回结构错误,并给出修复代码。
适用人群
- 使用n8n搭建自动化流程的开发者
- 需要在n8n中处理Python数据逻辑的工程师
- 负责Webhook和API数据清洗的自动化运营人员
- 正在排查n8n Python Code节点错误的用户
使用步骤
- 说明n8n节点任务、运行模式和示例输入
- 确认使用Python而不是JavaScript或专用节点
- 选择_input、_json或_node的数据访问方式
- 生成并检查带json包装的返回结果
- 在n8n中运行测试并根据报错修正
开始使用
将需求和 Skill 名称发送给已连接 SkillPX MCP 的 AI 助手,核对适用工具和安装要求。
技术信息
- 分类
- 编程
- 适用工具
- Codex、Claude Code、OpenClaw、Hermes Agent、国内 Agent
- 使用难度
- 进阶
- 版本
- main
- 最近更新
- 2026-11-03
- 文件数
- 4
- 安装包大小
- 自动生成 ZIP
- 安全检查
- 基础检查通过
Write Python code in n8n Code nodes. Use when writing Python in n8n, using _input/_json/_node syntax, working with standard library, or need to understand Python limitations in n8n Code nodes. Use this skill when the user specifically requests Python for an n8n Code node. Note — JavaScript is recommended for 95% of use cases — only use Python when the user explicitly prefers it or the task requires Python-specific standard library capabilities (regex, hashlib, statistics). EXCEPTION — for Python in the AI-agent-callable Custom Code Tool (@n8n/n8n-nodes-langchain.toolCode), use the n8n-code-tool skill instead (input is _query, return must be a string).