0
votes

Below is the code,

import logging
import json 
import urllib.request
import urllib.parse
import azure.functions as func


def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    response = urllib.request.urlopen("http://example.com:5000/processing")
    return {
        'statusCode': 200,
        'body': json.dumps(response.read().decode('utf-8'))
    }

Error: Result: Failure Exception: RuntimeError: function 'abc' without a $return binding returned a non-None value Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 341, in _handle__invocation_request f'function {fi.name!r} without a $return binding '. The same code works in lambda.. Please help me in debugging in azure functions.

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "sourcemetadata/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
1
Could you please provide your funtion.json file?Jim Xu
@JimXu Added function.json aboveRaphael Titus
@JimXu If i have folder structure inside container .. Container name : abc Folder name : example... How can i define path in function.json? ---- "path": "abc/example/{name}.csv",Raphael Titus

1 Answers

0
votes

In the Azure function, if you use return in the function app code, it means that you want to use output binding. But you do not define it in function.json. Please define it. For more details, please refer to here and here

For example

I use process blob with blob trigger and send message to azure queue with queue output binding

  1. function.json
{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "test/{name}.csv",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "$return",
      "direction": "out",
      "type": "queue",
      "queueName": "outqueue",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
  1. Code
async def main(myblob: func.InputStream) :
    
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n")
    return "OK"

enter image description here enter image description here