0

After setting up an azure function using VScode, Python V2 on Windows & using quickstart directions, and sample from here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python-v2%2Cin-process&pivots=programming-language-python

Additionally I also set it up within a trigger to test:

@app.timer_trigger(schedule="*/5 * * * * *", arg_name="myTimer", run_on_startup=True,
              use_monitor=False) 
@app.blob_input(arg_name="inputblob",
                path="samples/test.txt",
                connection="AzureWebJobsStorage")
@app.blob_output(arg_name="outputblob",
                path="newblob/test.txt",
                connection="AzureWebJobsStorage")
#def TimerTrigger(myTimer: func.TimerRequest, inputblob: str, outputblob: func.Out[str]) -> None:
def TimerTrigger(myTimer, inputblob, outputblob) :
    
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')
    logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
    outputblob.set(inputblob)
    return "ok"

Consistently getting errors which are variations of:

Executed 'Functions.TimerTrigger' (Failed, Id=b1ab178c-e66a-4bbe-9ee6-bc9dc9241120, Duration=15ms) [2023-08-15T19:59:55.023Z] System.Private.CoreLib: Exception while executing function: Functions.TimerTrigger. System.Private.CoreLib: Result: Failure Exception: TypeError: object of type 'NoneType' has no len() Stack: File "C:\Users\T8\AppData\Roaming\nvm\v16.18.0\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 479, in _handle__invocation_request call_result = await self._loop.run_in_executor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\T8\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\T8\AppData\Roaming\nvm\v16.18.0\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 752, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\T8\AppData\Roaming\nvm\v16.18.0\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper result = function(**args) ^^^^^^^^^^^^^^^^ File "C:\Users\T8\source\repos\Q8Utilities\filefuncapp\function_app.py", line 50, in TimerTrigger logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')

Expecting this should just run. Updated to Python 3.11, same result.

I've tried providing the data_type parameter to the blob_input() argument list. Same result

I've also tried using InputStream for the blob & using the read() method. Same error. def HttpTriggerFile(req: func.HttpRequest, obj: func.InputStream) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') logging.info(f'Python HTTP-triggered function processed: {obj.read()}')

What am I missing? Is the provided code incorrect? Some kind of setup issue?

Thanks

1 Answer 1

1

Encountering a NoneType error when accessing the blob. The error occurs when a variable or object that you expect to contain a value (not None) actually contains None.

  • The Blob Trigger function listens for changes in a blob container and processes the input blob by copying its content to an output blob and runs on a scheduled basis and logs the execution time.
  • I tried below code :
import datetime
import logging
import azure.functions as func

app = func.FunctionApp()

# Blob Trigger Function
@app.function_name(name="BlobOutput1")
@app.route(route="file")
@app.blob_input(arg_name="inputblob",
                path="samples/test.txt",
                connection="AzureWebJobsStorage")
@app.blob_output(arg_name="outputblob",
                path="newblob/test.txt",
                connection="AzureWebJobsStorage")
def main(req: func.HttpRequest, inputblob: str, outputblob: func.Out[str]):
    logging.info(f'Python Queue trigger function processed {len(inputblob)} bytes')
    outputblob.set(inputblob)
    return "ok"

# Timer Trigger Function
@app.schedule(schedule="*/5 * * * * *", arg_name="myTimer", run_on_startup=True, use_monitor=False) 
def TimerTrigger(myTimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

Output:

enter image description here

enter image description here

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

4 Comments

Thanks. Are you able to try the blob code within the timer trigger ? Just need to confirm, as I used your example and still get the error when "BlobOutput1" is run with an httpRequest. The code provided looks essentially the same as mine, which I think is part of the puzzle: "If the code is the same, what in the environment could cause the difference in runtime behavior ?"
Yes ,able to use this blob code within the timer trigger. selected v2 and timer trigger in the path give container/blobname and in local.setting.json place connectionstring in "AzureWebJobsStorage": " DefaultEndpointsProtocot " - Python 3.10.9
path as sam/hello.txt a sample hello.txt upload with some content and sam2/hello2.txt a sample hello.txt upload with no content Image
Yeah, still getting the same error. Must be some issue in the azure functions environment manifesting itself here.

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.