Skip to content Skip to sidebar Skip to footer

Importing Azure Blob Via Sas In Python

EDIT: I am looking to import a blob from an Azure Storage Container into my Python script via a BLOB-specific SAS. from azure.storage.blob import BlobService sas_service = BlobSe

Solution 1:

According to your description , you want to access azure blob storage via SAS_TOKEN.

You could refer to the snippet of code as below which works for me:

from datetime import datetime, timedelta
import requests
from azure.storage.blob import (
    BlockBlobService,
    ContainerPermissions,
)

accountName = "<your_account_name>"
accountKey = "<your_account_key>"
containerName = "<your_container_name>"
blobName = "<your_blob_name>"defGetSasToken():
    blobService = BlockBlobService(account_name=accountName, account_key=accountKey)
    sas_token = blobService.generate_container_shared_access_signature(containerName,ContainerPermissions.READ, datetime.utcnow() + timedelta(hours=1))
    return sas_token


defAccessTest(token):
    blobService = BlockBlobService(account_name = accountName, account_key = None, sas_token = token)
    blobService.get_blob_to_path(containerName,blobName,"E://test.txt")


token=GetSasToken()
print token
AccessTest(token)

You could also refer to more details from official tutorial.

Hope it helps you.

Solution 2:

Post a Comment for "Importing Azure Blob Via Sas In Python"