Zapier给出错误:Python脚本的'unicode'对象没有属性'copy'`

时间:2019-01-20 14:29:06

标签: python json python-2.7 datetime zapier

脚本很简单:

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

如何使此代码运行?这是什么问题?

1 个答案:

答案 0 :(得分:2)

Zapier希望脚本的输出是JSON可序列化的对象(从注释部分向Michael Case致谢)。

此外,脚本未正确缩进。 Python是一种缩进敏感的语言,即缩进很重要。

尝试这样的事情:

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)}