【问题标题】:OpenWhisk Python action failing with not returning dictionary errorOpenWhisk Python 操作失败,未返回字典错误
【发布时间】:2018-06-14 02:13:21
【问题描述】:

我正在尝试使用 OpenWhisk 运行此功能:

def main():
    return {"payload": "Hello world"}

以下内容:

> bx wsk action create hello_python hello_python.py
> bx wsk action invoke hello_python

在本地运行该函数时,会返回一个字典,但运行上述内容会出现此错误:

"result": {
        "error": "The action did not return a dictionary."
    }

我在这里错过了什么?

【问题讨论】:

    标签: python ibm-cloud openwhisk ibm-cloud-functions


    【解决方案1】:

    将您的代码更改为:

    def main(args):
        return {"payload": "Hello world"}
    

    The Python actions consume and produce a dictionary。因此,您需要“args”。

    【讨论】:

    • 这看起来和我的完全一样,是 def main(args) 中缺少的 args。感谢您提供文档链接!
    • 对不起,当我复制你的代码时,我忘了添加“args”。现在答案是正确的。
    【解决方案2】:

    main() 输入不能为空需要一个类似于 main(args) 的字典

    def main(args):
        return {"payload": "Hello world"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2015-08-11
      • 2017-03-08
      • 2021-09-29
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多