Это немного сложно.Я столкнулся с той же проблемой и обнаружил, что клиент Python API не включает повторные попытки для метода upload_from_string ().
Все функции upload_from_string () - это вызов метода upload_from_file (), который имеет повторные попытки, но реализация игнорирует повторные попытки.
def upload_from_string(self,
data,
content_type="text/plain",
client=None,
predefined_acl=None):
data = _to_bytes(data, encoding="utf-8")
string_buffer = BytesIO(data)
self.upload_from_file(
file_obj=string_buffer,
size=len(data),
content_type=content_type,
client=client,
predefined_acl=predefined_acl,
)
Вы можете взломать метод upload_from_string (), используя upload_from_file () реализация, добавив повторных попыток:
from google.cloud._helpers import _to_bytes
from io import BytesIO
from google.cloud.storage import Blob
def upload_from_string(
data, file_path, bucket, client, content_type, num_retries
):
data = _to_bytes(data, encoding="utf-8")
string_buffer = BytesIO(data)
blob = Blob(file_path, bucket)
blob.upload_from_file(
file_obj=string_buffer,
size=len(data),
client=client,
num_retries=num_retries,
content_type=content_type
)