Azure / Azure/azure-storage-python

How to handle timeout for Uploading a blob in Azure Storage using Python SDK?

Đang mở
#711 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
343
Fork
243
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the BlobClient.upload_blob call and the timeout values shown in the issue, then compare its behavior with the retry wrapper and the ServiceRequestError output. Done means establishing and documenting the expected timeout behavior for failed Azure Storage connections, with a reproducible test or clarified guidance.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
azure, python
Lĩnh vực
cloud
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.