Python eval() not functioning as normal non-Pyodide Python

Describe the problem/error/question

I am currently building a data transformation node using the Python code node. I understand that it is using Pyodide in the background, but for my use case it has been functioning identically to regular Python. I am currently trying to build some logic that evaluates a string as a literal Python statement. I have tested this outside of n8n and in a Python IDE and works as expected.

def key_to_value(data, data_name):
    for item in data:
        key = data[item]['key']
        value_type = data[item]['type']
        value_in_string = str(data_name + key)
        value = eval(value_in_string)

What is the error message (if any)?

ERROR: NameError: name ‘json_webhook’ is not defined

Note: json_webhook is the output from the webhook node

Information on your n8n setup

  • n8n version: 1.25.1
  • Database (default: SQLite)
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via n8n cloud

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hey @ryan.greene,

Can you share the full code you are using? The error would suggest you are using a variable that is not defined so it would be handy to see where you are pulling that from in your code.