You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Azure Cloud Storage throws ImportError for BlockBlobService #125
Don't have time to open a PR, but ran into the same issue. The problem was that Azure updated their CLI. Update the MAS class in the _clouds.py file to the following:
class MAS(Clouds):
def __init__(self, **options):
"""
@TODO: add documentation
"""
try:
from azure.storage.blob import BlobServiceClient
connection_string = options.get('connection_string')
if not connection_string:
raise ValueError("A connection string must be provided")
self.blob_service_client = BlobServiceClient.from_connection_string(connection_st
ring)
except ImportError as e:
raise ImportError("Make sure that you have installed the azure-storage-blob packa
ge via pip:\n\n"
"pip install azure-storage-blob")
def upload_directory(self, directory, **options):
container_name = options.pop('container', None)
if container_name is None:
raise ValueError('You should pass a container name')
files = [f for f in listdir(directory) if isfile(join(directory, f))]
try:
container_client = self.blob_service_client.get_container_client(container_name)
for file in files:
blob_client = container_client.get_blob_client(file)
with open(join(directory, file), "rb") as data:
blob_client.upload_blob(data)
except Exception as e:
error = f"An error occurred while uploading the directory: {str(e)}"
logging.error(error)
raise RuntimeError(error)
def download(self, filename=None, **options):
container = options.pop('container', None)
blob = options.pop('blob', None)
if container is None or blob is None:
raise ValueError('You should pass a container name and a blob name')
if filename is None:
with tempfile.NamedTemporaryFile(prefix=basename(blob), delete=False) as tmp:
filename = tmp.name
try:
self.block_blob_service.get_blob_to_path(container, blob, filename)
logging.info("The " + filename + " file was downloaded")
except:
error = "An error occurred while downloading the file"
logging.error(error)
raise RuntimeError(error)
return filename
Activity
forrestberry commentedon Jan 12, 2024
Don't have time to open a PR, but ran into the same issue. The problem was that Azure updated their CLI. Update the MAS class in the _clouds.py file to the following:
Azure Docs: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-cli
Update to the docs:
Instead of providing:
mas = MAS(account_name='account_name', account_key='account_key')provide:
mas = MAS(connection_string='your_connection_string')