First of all, I am not a Python expert. I am just trying to let you know what the issue is all about.
So on Azure function if you look, it would seem its return type is IActionResult
. If you decompile
it, you would see:
IActionResult IConvertToActionResult.Convert()
{
ActionResult result = this.Result;
if (result != null)
return (IActionResult) result;
return (IActionResult) new ObjectResult((object) this.Value)
{
DeclaredType = typeof (TValue)
};
}
So it expects an object from you rather than a Dictionary or List or any kind of generics type. But if you convert it into an object like OkObjectResult
, you wouldn't encounter any compile error. See the example below:
IDictionary<int, string> MyDictionary = new Dictionary<int, string>();
MyDictionary.Add(new KeyValuePair<int, string>(1, "One"));
MyDictionary.Add(new KeyValuePair<int, string>(2, "Two"));
// As we have to return IAction Type, so converting to IAction class
// using OkObjectResult we can even use OkResult
return new MyDictionary;
The above code would encounter your compile error. Because it does not support Dictionary or List Or any generic directly. See the screenshot below:

See what the error said:

But if you convert your Dictionary or List Or any generic into an object type, it will resolve your issue for sure. See the below example:
IDictionary<int, string> MyDictionary = new Dictionary<int, string>();
MyDictionary.Add(new KeyValuePair<int, string>(1, "One"));
MyDictionary.Add(new KeyValuePair<int, string>(2, "Two"));
// So have converted MyDictionary into Object type that the compiler deserve. And no compile error encountered.
return new OkObjectResult(MyDictionary);
See the screenshot below:

Note: If you try to parse your func.HttpResponse(name)
into an object then finally return, your problem should resolve. So you can try to add a reference to this package in your project (import json
) and try the below code:
import json
name = {"test":"jjj"}
print(json.dumps(name))