Why I can't import libary azure.storage.blob

Peter Macfie 0 Reputation points
2024-11-02T13:34:10.6166667+00:00

When I add the following line into my code of my function app, the whole function app fails to load

from azure.storage.blob import BlobServiceClient

If I remove the above line, then it works fine.

import azure.functions as func

import logging

from azure.storage.blob import BlobServiceClient

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="http_trigger5")

def http_trigger5(req: func.HttpRequest) -> func.HttpResponse:

*logging.info('Python HTTP trigger function processed a request.2')*

*name = req.params.get('name')*

*if not name:*

    *try:*

        *req_body = req.get_json()*

    *except ValueError:*

        *pass*

    *else:*

        *name = req_body.get('name')*

*if name:*

    *return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")*

*else:*

    *return func.HttpResponse(*

         *"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",*

         *status_code=200*

    *)*

*@app.timer_trigger(schedule="0 */5 * * * ", arg_name="myTimer", run_on_startup=False,

          *use_monitor=False)* 

def timer_trigger1(myTimer: func.TimerRequest) -> None:

*if myTimer.past_due:*

    *logging.info('The timer is past due!')*

*logging.info('Python timer trigger function executed.')*

I have tried adding a requirement.txt file with the dependencies in, and restarted the web app.

What is strange is there is no error, the function simply disappears.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,927 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,917 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 26,491 Reputation points
    2024-11-02T14:11:44.42+00:00

    Have you verified if azure-storage-blob library version is compatible with your Python runtime?

    You can check this by adding the library version explicitly in requirements.txt:

    
    azure-storage-blob==12.x.x  # Replace with a compatible version number
    
    

    Run pip show azure-storage-blob in your local development environment and check the Azure Function App logs for installation details during deployment.

    After updating requirements.txt, restart the Function App to ensure the new dependencies are loaded. Clear any cached packages or artifacts if possible.

    You can add more logging before the import line to see if any errors are logged just before the app fails:

    
    logging.info("Starting import of BlobServiceClient")
    
    from azure.storage.blob import BlobServiceClient
    
    logging.info("Import successful")
    
    
    0 comments No comments

  2. Nehruji R 8,146 Reputation points Microsoft Vendor
    2024-11-04T05:45:33.34+00:00

    Hello Peter Macfie,

    Greetings! Welcome to Microsoft Q&A Forum.

    Can you kindly try out from your end by running pip install azure-storage --upgrade.

    Make sure you are using Python 3.8 or later, as this is required to use the Azure Storage Blobs client library. Also refer this doc for detailed steps and please provide more details about the error message you are encountering.

    Additionally, check if there are any typos or incorrect paths in your code. Sometimes, the error might be due to a simple mistake in the code.

    refer some troubleshooting docs - https://learn.microsoft.com/en-us/troubleshoot/azure/azure-storage/blobs/welcome-blob-storage, https://learn.microsoft.com/en-us/troubleshoot/azure/azure-storage/blobs/alerts/storage-monitoring-diagnosing-troubleshooting?tabs=dotnet.

    Hope this information helps! please let us know if you have any further queries. I’m happy to assist you further.


    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.