无法使用Google Cloud Scheduler调用Google Cloud函数

2024-05-04 04:23:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python 3.7创建了一个Google云函数。通过测试函数本身,它的行为符合预期。我已经将函数的触发器设置为一个名为“Scheduled”的主题

enter image description here

当从UI手动测试时,代码本身运行一系列API调用,完全按照预期工作。 Output when running a manual test. 原始源代码不需要脚本中主函数的参数,但是我意识到云函数无论如何都会传递2,因此我添加了它们,但没有实际用途:

def main(event, data):
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    getNotifs = getNotifications()
    if getNotifs["hasData"] == True:
        print("Found notifications, posting to Telegram.")
        notifsParsed = parseNotifications(getNotifs["data"])
        telegramCall = telegramPost(
            {"text": str(notifsParsed), "chat_id": ChatId, "parse_mode": "HTML"})
        print(telegramCall)
    elif getNotifs["hasData"] == False:
        print(getNotifs["error"])
    print("================================")

现在,我创建了一个新的云调度程序作业,其中目标是“发布/订阅”,主题也是“调度”。我在任何地方都找不到所需的“有效载荷”字段的用法,而Google的Scheduler guide只填写了一个随机值,“hello”没有引号或类似的内容,所以我填写了“hi”

enter image description here

运行作业时,我多次遇到失败,此日志: 状态:“无效参数”
目标类型:“发布订阅”

我尝试将有效负载更改为“hi”(带引号),编辑主PY函数以接受另一个参数,两者似乎完全无关。我错过了什么


Tags: 函数目标主题data参数google作业hi