0

I´m trying to download a file from Azure blob storage to to Azure Functions-App temp folder with python.

blobClient = BlobClient.from_connection_string(
    conn_str = os.getenv('CONNECTION_STRING'), 
    container_name = 'data', 
    blob_name = 'data.csv'
)

filepath = os.path.join(tempfile.gettempdir(), 'data.csv')

with open(file = filepath, mode="wb") as file:
    downloadStream = blobClient.download_blob()
    file.write(downloadStream.readall())

On my local development environment it works well without any errors (connection string to cloud blob storgae, not local Azurite), but if i run the Functions-App on cloud environment I get following error:

Result: Failure Exception: HttpResponseError: The specifed resource name contains invalid characters.
[...]
line 366, in __init__ self._response = self._initial_request() File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_download.py", line 466, in _initial_request process_storage_error(error) File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_shared/response_handlers.py", line 189, in process_storage_error exec("raise error from None") # pylint: disable=exec-used # nosec File "<string>", line 1, in <module>

Same error appears for upload_blob() in other Functions-App.

I´ve found some similar questions and answers, like no special characters (naming convention) or only blob name not full path but nothing worked for me so far.

3
  • What's the value of your connection string? Commented Mar 4, 2023 at 2:27
  • It´s the common connection string I´ve received with ''az storage account show-connection-string -g MyResourceGroup -n MyStorageAccount'' Commented Mar 4, 2023 at 18:05
  • I don't see an issue with the container name or blob name. Only thing I could think of is invalid connection string. Have you set the environment variable correctly? Can you try to execute other method like exists() on the blob client? Commented Mar 4, 2023 at 18:13

1 Answer 1

0

I tried to run the function app in my local environment with a wrong container or blob name & I received a similar error code as yours and also check whether the container and blobs are present in the blob storage:-

enter image description here

I deployed my HTTP Trigger function with the code below in the Function app of my Azure Portal:-

_init_.py

import logging
from azure.storage.blob import BlobClient
import tempfile
import os

import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    blobClient = BlobClient.from_connection_string('<connection-string>;EndpointSuffix=core.windows.net','container-name', 'blob-name')
    filepath = os.path.join(tempfile.gettempdir(), 'secret.txt')
    with open(file = filepath, mode="wb") as file:
      downloadStream = blobClient.download_blob()
      file.write(downloadStream.readall())
      return func.HttpResponse(filepath)

Used the commands below to deploy my Function from the local environment to Azure Portal:-

az login
az account set --subscription "<subscription-name>"
func azure functionapp publish app326

HTTP function got deployed in Azure successfully like below:-

Output:-

enter image description here

Now, When I browse my Azure Function URL, I get the temp file location like the below:-

https://<functionapp>.azurewebsites.net/api/HttpTrigger1

Portal:-

enter image description here

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

Comments

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.