1

I am using a blob trigger to read the blob contents, process as a pandas DF and append the blob to the Azure SQL server I am using.

The blob trigger didn't work as expected so I defined all code in the main function as such:

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")
    file = re.sub(r'^(.*?)\/','',myblob.name)
    if file not in processedfiles:
        stream = BytesIO((myblob.read()))
        stream.seek(0)

However I get the following error:

Exception: FunctionLoadError: cannot load the BlobFileTrigger function: 
binding myblob has invalid non-type annotation <sqlalchemy.sql.functions._FunctionGenerator object at 0x7faa340f6a00>

Can someone help me find the cause of this issue?

The function.json is configured as follows:

{
  "scriptFile": "__init__.py",
  "disabled": false,
  "bindings": [
      {
          "name": "myblob",
          "type": "blobTrigger",
          "direction": "in",
          "path": "input/{name}",
          "connection":"StorageConnection"
      }
  ]
}
Stijn
  • 121
  • 9

1 Answers1

1
  • The configured function.json file is fine.

  • If you are getting an empty byte string, so use the seek(0) method first then Read() from stream.

  • Make sure that if condition is proper on the processedfiles, because if it's not found any files in processedfiles then only your case will execute.

    i.e.:- stream = BytesIO((myblob.read()))

Reference: read() and getvalue() methods of Python io.BytesIO

Azure Functions with Blobtrigger in Python

RajkumarPalnati
  • 541
  • 2
  • 6
  • 1
    It seems importing azure.functions as func collides with func from sqlalchemy, i'll rename and try again. https://learn.microsoft.com/en-us/answers/questions/568041/sqlalchemy-incompatible-with-python-azure-function.html – Stijn May 25 '22 at 14:19
  • @Stijn, try with that name like **az_func** like that and check. – RajkumarPalnati May 25 '22 at 14:25
  • yes, thanks again! After renaming to az_func the script worked as intended! – Stijn May 27 '22 at 12:48