0
votes

i'm trying to download blob from sub-directory of azure blob . i'm only able to download few files but for remaining it is throwing "HTTP status code=416, Exception=The range specified is invalid for the current size of the resource. ErrorCode: InvalidRange" . i am able to directly download the blobs from azure but programmatically only few were downloaded

3
Welcome to the site. Please add more details about your current python implementation. - EmJ
Please add the code and what specifically you're trying to accomplish. Are the blobs within a virtual folder, or a container, also did you speciffy any range/size limits for the blobs to be downloaded ? - Adam Smith - Microsoft Azure

3 Answers

2
votes

I got this error, when I tried to download an empty blob. Using Peter Pan's code, you need to add a check for emptiness.

blob_info = blob_service.get_blob_properties(container_name, blob_name)
if blob_info.properties.content_length == 0:
    return "empty blob"
0
votes

Here is the description about your error, please refer to the offical document Common REST API Error Codes for Storage Services.

enter image description here

Due to there is not any code in your description, I post my sample code as reference at here.

from azure.storage.blob.baseblobservice import BaseBlobService

import os

account_name = '<your account name>'
account_key = '<your account key>'

blob_service = BaseBlobService(
    account_name=account_name,
    account_key=account_key
)

container_name = '<your container name, such as `test`'

# Virtual Directory Name as the prefix string of a blob name
prefix = '<the blob name prefix, such as `images`>' 

# local directory path for downloading blobs
local_path = '<a local directory path for downloading, such as `download`>' 

blobs = blob_service.list_blobs(container_name, prefix=prefix)

for blob in blobs:
    blob_name = blob.name
    blob_base_name = os.path.basename(blob_name)
    file_path = '%s/%s' % (local_path, blob_base_name)
    blob_service.get_blob_to_path(container_name, blob_name, file_path)

Hope it helps.

0
votes

Most likely you get these exceptions for blobs with zero length. Here (Microsoft Azure Storage SDK for Python issues: https://github.com/Azure/azure-storage-python/issues/586) they say that you are safe to ignore these exceptions - catch and swallow. Such files are still downloaded correctly:

I believe this error is shown when you try to download a zero-length blob. You can get around it by checking the blob properties prior to trying the download, or alternatively just let it happen - the file is downloaded as it should be anyway.

I verified it and can confirm that zero-length files are downloaded correctly if these exceptions are swallowed.