I created a basic script for performing availability checks using Shadowrun 5E rules with data pulled from a Google Form through Zapier. Unfortunately, I encounter an issue where Zapier signals an error every time I execute it. Everything seems correctly set up, so what might be the source of this problem?
import random
item_pool = int(input_data.get('itempool'))
opposed_pool = int(input_data.get('opposedpool'))
item_loops = 0
item_successes = 0
opposed_loops = 0
opposed_successes = 0
while item_loops < item_pool:
die_result = random.randint(1, 6)
item_loops += 1
if die_result >= 5:
item_successes += 1
while opposed_loops < opposed_pool:
die_result = random.randint(1, 6)
opposed_loops += 1
if die_result >= 5:
opposed_successes += 1
return {'opposed_success': opposed_successes, 'item_success': item_successes}
I receive the following error message: “Bargle. An error occurred while creating the Python run. Error: Your code encountered an error!”. I also tested a different script that only generates a random number which worked fine, suggesting there might be an issue with my while loops.
Edit 2: After bypassing the test step in Zapier, I identified this error: Sent to Code “Run Python” failed: Your code had an error! Traceback (most recent call last): File “/tmp/tmpQdoNPW/usercode.py”, line 16, in the_function die_result = random.randint(1, 6) NameError: global name ‘random’ is not defined.