Search code examples
pythonapiibm-cloudopenwhisk

openwhisk error: "The action did not return a dictionary."


when trying to invoke an openwhisk action, I'm getting a 400 error with the following result and log:

Results:

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

Logs

[
"2018-02-12T20:20:27.224409701Z stderr: Traceback (most recent call 
last):",
"2018-02-12T20:20:27.224534535Z stderr: File \"pythonrunner.py\", line 
88, in run",
"2018-02-12T20:20:27.224550304Z stderr: exec('fun = %s(param)' % 
self.mainFn, self.global_context)",
"2018-02-12T20:20:27.224559746Z stderr: File \"<string>\", line 1, in 
<module>",
"2018-02-12T20:20:27.224578509Z stderr: File \"__main__.py\", line 308, 
in main",
"2018-02-12T20:20:27.224587541Z stderr: if 
datos_usuario[\"__ow_method\"] 
== \"get\":",
"2018-02-12T20:20:27.224596543Z stderr: KeyError: '__ow_method'"
]

The action used to work correctly until now, which makes me think that the error could be related to specific issues accessing the API. Any ideas on how I could get around this issue?

Thanks!


Solution

  • You'll need to create that action as a webaction. The error hints to the fact that __ow_method is not present, which is only present if your action is a webaction.

    Does your action do anything with that field? If you want to write your action conditionally (as in: detect if it's actually a webaction) you'll need to check if the field is actually present. In python, you'd use get() to either get the key or None.

    In terms of not returning anything meaningful: Seems like your action crashes randomly without doing anything with that error. Potentially the runtime itself could be updated to catch any uncaught errors and return something more meaningful. An issue against the repository might be warranted in that case.