Vincenzo Sciacca
Vincenzo Sciacca

Reputation: 21

I'm getting Value 'func.Out' is unsubscriptable trying to write in an azure blob storage using a python function

I want to write in an azure blob storage using Azure Functions in Python.

I'm using the output blob storage bindings for Azure Functions.

My function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "inputblob",
      "type": "blob",
      "path": "{containerName}/{blobName}.json",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "path": "{containerName}/{blobName}.json",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

And my Python code looks like this:

    import logging
    import azure.functions as func
    import azure.storage.blob
    from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
    import json, os

    def main(req: func.HttpRequest, inputblob: func.InputStream, outputblob: func.Out[func.InputStream]) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')

        # Initialize variable for tracking any changes
        anyChanges= False

        # Read JSON file
        jsonData= json.loads(inputblob.read())

        # Make changes to jsonData (omitted for simplicity) and update anyChanges

        # Upload new JSON file
        if anyChanges:
            outputblob.set(jsonData)

        return func.HttpResponse(f"Input data: {jsonData}. Any changes: {anyChanges}.")

However, this isn't working at all, with the following error being thrown:

Value 'func.Out' is unsubscriptable

Another guy in December already asked for a resolution to the same issue, but the answer does not solve the issue

Upvotes: 2

Views: 1630

Answers (3)

Métoule
Métoule

Reputation: 14512

Instead of uninstalling pylint, you can simply disable that specific warning:

# pylint: disable=unsubscriptable-object
def main(req: func.HttpRequest, inputblob: func.InputStream, outputblob: func.Out[func.InputStream]) -> func.HttpResponse:
    # your code

Upvotes: 0

Vitalii Kozhukhivskyi
Vitalii Kozhukhivskyi

Reputation: 63

I've had the same issue, and I actually found out that's the problem is resolved by removing pylint library:

pip uninstall pylint

I am not sure if that is a problem in pylint or if Azure Functions cannot coexist with pylint in Python 3.7, but removing it did the trick for me.

Upvotes: 1

acmcg
acmcg

Reputation: 31

Same issue using 3.7.0 switched to 3.6.8 to solve it

Upvotes: 3

Related Questions