Azure / Azure/azure-storage-python

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

オープン
#711 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
343
フォーク
243
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
azure, python
領域
cloud
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。