Evan Cory Levine
Evan Cory Levine

Reputation: 65

Zapier gives error: `'unicode' object has no attribute 'copy'` for Python script

The script is simple:

import datetime
import json

today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
    if 15 <= next_thursday.day <= 21:
        next_third_thursday = next_thursday
        break
    else:
        next_date = next_thursday + datetime.timedelta(days=1)
        next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))

return json.dumps({'date': str(next_third_thursday)})

enter image description here

How do I get this code to run? What's the issue here?

Upvotes: 2

Views: 1695

Answers (1)

Milan Cermak
Milan Cermak

Reputation: 8064

Zapier expects the output of the script to be a JSON-serializable object (h/t to Michael Case from the comments section).

Furthermore, the script is not indented properly. Python is an indentation-sensitive language, i.e. indentation matters.

Try something like this:

import datetime

today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
    if 15 <= next_thursday.day <= 21:
        next_third_thursday = next_thursday
        break
    else:
        next_date = next_thursday + datetime.timedelta(days=1)
        next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))

return {'date': str(next_third_thursday)}

Upvotes: 2

Related Questions