I am encountering a 403 error when attempting to iterate over blobs in my Azure Storage container using the container_client.list_blobs()
method. The error occurs specifically when entering the for loop. Here is the relevant part of my code:
# option 1:
def get_folders_from_last_month(self, container_client):
today = datetime.today()
current_year_month = today.strftime('%Y_%m')
try:
blobs = container_client.walk_blobs(name_starts_with=current_year_month)
logging.info('Listing blobs with prefix %s', current_year_month)
folders = set()
for blob in blobs:
logging.info('Processing blob: %s', blob.name)
folder = blob.name.split('/')[0]
if self.is_valid_date(folder):
folders.add(folder)
return folders
except Exception as e:
logging.error('Error occurred: %s', str(e))
raise
# option 2:
def get_folders(self, container_client):
try:
blobs = container_client.list_blobs()
logging.info('blobs %s', blobs)
folders = set()
for blob in blobs:
folder = blob.name.split('/')[0]
logging.info('folder %s', folder)
if self.is_valid_date(folder):
folders.add(folder)
return folders
except Exception as e:
logging.error('Error occurred: %s', str(e))
raise
I have ensured that my credentials and permissions are correct. I have tried connecting to the container using both a SAS token and a connection string, but the issue persists. Any guidance on resolving this would be appreciated.