Azure / Azure/azure-storage-python
How to handle timeout for Uploading a blob in Azure Storage using Python SDK?
- Dominant language
- Python
- Stars
- 343
- Forks
- 243
- PR merge metrics
- No merged PRs in 30d
Description
### Which version of the SDK was used? Please provide the output of `pip freeze`.
azure-storage-blob==12.13.1
### What problem was encountered?
I am trying to upload a blob to Azure Storage using Python SDK but I am unable to manage the timeout. The behavior of all timeout values are same.
```
from azure.storage.blob import BlobServiceClient, ContentSettings
from datetime import datetime
STORAGE_CONNECTION_STRING = ''
container = ''
blobFileName = ''
contentType = ''
def upload_blob(localFilePath):
blob_service_client = BlobServiceClient.from_connection_string(STORAGE_CONNECTION_STRING)
blob_client = blob_service_client.get_blob_client(container=container, blob=blobFileName)
content_setting = ContentSettings(content_type=contentType)
with open(localFilePath, "rb") as data:
blob_client.upload_blob(data, overwrite=True, content_settings=content_setting, timeout=30)
@retry(Exception, tries=5, delay=1)
def uploadImageToAzure(imagePath):
try:
upload_blob(imagePath)
except Exception as ex:
print(f'Exception: {ex}, Type:{type(ex)}, Time:{datetime.now()}')
raise Exception(ex)
print('Successfully Uploaded the File')
return True
uploadImageToAzure(imagePath)
```
To check the behavior of timeout. I just turn off my internet during uploading the blob.
Test Cases:
I just pick the random values of timeout and saw the behavior of the above code
- timeout=1
`Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:25:42.543262
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:27:04.949785
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:28:28.508035
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:29:58.473318
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:31:19.184696`
- timeout=2
`Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:46:25.328502
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:47:50.919091
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:49:14.144449
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:50:43.947462
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:52:05.272197`
- timeout=4
`Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:57:27.401257
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 09:58:55.699520
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:00:18.315710
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:01:37.800908
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:03:02.293558`
- timeout=16
`Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:19:15.195291
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:20:47.769388
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:22:14.996163
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:23:37.736138
Exception: : Failed to establish a new connection: [Errno -3] Temporary failure in name resolution, Type:, Time:2023-03-28 10:25:00.846901`
Contributor guide
Assessment
This issue has not been assessed yet.