2

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"
    }
  ]
}
3
  • Could you please provide your funtion.json file? Commented Jul 9, 2020 at 2:52
  • @JimXu Added function.json above Commented Jul 9, 2020 at 5:52
  • @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", Commented Jul 13, 2020 at 8:33

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Jim Xu for clarifying how "return" works with azure functions. I have configured the same and it works well.
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",
Yes you can define path like that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.