-1

How do I use a queue output binding in a python azure function. Here is the binding in my function.json

{
  "type": "queueTrigger",
  "name": "myQueue", 
  "direction": "out",
  "queueName": "qname",
  "connection": "CONNECTION"
}

My code ends with this

open(os.environ[myQueue], ‘wb’) as q:
    q.write(‘message’)

I just get an error to do with being unable to open QueueAttribute for writing. Anyone had experience with this because there is no documentation at all.

bastelflp
  • 9,362
  • 7
  • 32
  • 67
Virus7711
  • 27
  • 1
  • 5

1 Answers1

1

I tried to use queue storage output binding in a python azure function and it works well for me .I did not reproduce your issue.

You could refer to the steps I worked.

Step 1: Create HttpTrigger for Python.

enter image description here

Step 2: Configure queue storage output binding as below.

enter image description here

Step 3: Check run.py code and function.json

run.py

import os
import json

postreqdata = json.loads(open(os.environ['req']).read())
response = open(os.environ['res'], 'w')
response.write("hello world from "+postreqdata['name'])
response.close()

function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "queue",
      "name": "res",
      "queueName": "outqueue",
      "connection": "jaygong_STORAGE",
      "direction": "out"
    }
  ],
  "disabled": false
}

Step 4 :Run the function and check storage queue message.

enter image description here

You could also refer to the official tutorial and Queue Storage Output Binding Configuration.

Hope it helps you.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32