String splitting fails in Zapier Python code

I’m working with Zapier to connect multiple applications and I’m having trouble with a basic string operation. I have a field called order_reference that contains data with 6 segments separated by underscores, like ord123_p456_29.99_3_ABC_2023-05-15.

Here’s what I tried first:

parts = input_data['order_reference'].split("_")

result = [{'order_id': parts[0], 'product_code': parts[1], 'price': parts[2], 'quantity': parts[3], 'vendor': parts[4], 'order_date': parts[5]}]

I also attempted this approach:

order_id, product_code, price, qty, vendor, order_date = input_data['order_reference'].split("_")

result = [{'order_id': order_id, 'product_code': product_code, 'price': price, 'qty': qty, 'vendor': vendor, 'order_date': order_date}]

Both methods give me the same vague error from Zapier: “Oops! We encountered an issue running your Python code. Error: Your code encountered an error!”

I’ve tested similar code outside of Zapier and it works fine. Has anyone experienced issues with string splitting in Zapier’s Python environment? Any suggestions would be helpful!

EDIT: Found the issue! The test data was displaying correctly in the interface, but during execution input_data was actually empty. The splitting code was fine all along!

so true! it’s easy to get tricked by the test data. I usually try to log stuff too, helps a ton to debug the truth behind these issues. good luck!

I’ve hit this exact debugging nightmare with Zapier’s Python setup. The interface is super misleading - it shows sample data that looks perfect, but then the actual runtime data is completely different or just missing.

Always validate before doing operations like split(). Check if the field exists and has the underscores you expect. Throw in something like if 'order_reference' in input_data and input_data['order_reference']: before your split logic.

You’ll get actual error messages instead of Zapier’s useless generic failures. Saved me tons of time when the real problem was just empty or broken input data that the test interface didn’t show.

This happens way too often with Zapier’s Python code step. The test interface is misleading - it uses sample data that’s completely different from what you get in live runs. I always add defensive checks at the start now, especially with external data that might send null values or unexpected formats. Split will crash if it hits None or an empty string. What’s really annoying is Zapier’s error messages are useless for security reasons, so you never see the actual Python exception that would tell you what broke. I just build in basic validation and fallbacks for every Python step now.