Python code in Zapier fails with `'unicode' object has no attribute 'copy'` error

I’m trying to run a Python script in Zapier that calculates the third Friday of the current month. The code works fine when I test it locally but throws an error when executed in Zapier. Here’s my implementation:

import datetime
import json

current_date = datetime.date.today()
first_friday = current_date + datetime.timedelta(((4 - current_date.weekday()) % 7))

while True:
    if 15 <= first_friday.day <= 21:
        third_friday_date = first_friday
        break
    else:
        temp_date = first_friday + datetime.timedelta(days=1)
        first_friday = temp_date + datetime.timedelta(((4 - temp_date.weekday()) % 7))

return json.dumps({'calculated_date': str(third_friday_date)})

The error message mentions that a unicode object doesn’t have a copy attribute. I’m not sure what’s causing this issue since the script runs perfectly in my local Python environment. Has anyone encountered this problem before? What modifications do I need to make for this to work properly in Zapier’s Python environment?

This happens because Zapier handles Python differently than your local setup. The problem’s likely your return statement, not the date logic. In Zapier’s Python step, use the output dictionary instead of returning JSON directly. Change your final line to output = {‘calculated_date’: str(third_friday_date)} and ditch the return statement. Zapier handles output formatting automatically, so json.dumps creates type conflicts. Also stick to Python 3 syntax throughout - Zapier’s stricter about unicode handling than your local environment.

Yeah, I’ve hit this before - Zapier’s Python environment acts weird with json.dumps sometimes. Just use output = {‘calculated_date’: third_friday_date.strftime(‘%Y-%m-%d’)} and skip the json stuff. Your date logic’s more complex than it needs to be too, but that’s not what’s breaking it.

Had this exact problem last month migrating scripts to Zapier. The unicode error happens because Zapier’s data handling doesn’t play nice with json.dumps and return statements. Ditch both the json import and return statement completely. Change your last line to output = {'calculated_date': third_friday_date.isoformat()} and let Zapier format the output. Using isoformat() is cleaner than str() and won’t cause encoding headaches. Your date logic looks good - it’s just that Zapier’s Python runtime wants output handled differently than regular Python.