Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Cloud Storage throws ImportError for BlockBlobService #125

Open
vipulmittal07 opened this issue Sep 13, 2023 · 1 comment
Open

Azure Cloud Storage throws ImportError for BlockBlobService #125

vipulmittal07 opened this issue Sep 13, 2023 · 1 comment

Comments

@vipulmittal07
Copy link

Describe the bug
MAS throws ImportError as it is unable to find BlockBlobService in latest azure-storage-blob package

To Reproduce
Steps to reproduce the behavior:

  1. From ffmpeg_streaming import MAS
  2. Provide the credentials and try to run the python script
  3. Script breaks with ImportError

Expected behavior
ImportError shouldn't be thrown and MAS should work as expected

Screenshots
If applicable, add screenshots to help explain your problem.

Local machine (please complete the following information):

  • OS: Windows
  • FFMped [e.g. 4.1]

Additional context
Add any other context about the problem here.

@forrestberry
Copy link

forrestberry commented 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:

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

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants