我有一个代码可以从存储桶中读取文件,然后从所有文件元数据中编辑 content_encoding。它通常工作正常,但自从 3 天前我遇到了 google-cloud-storage API 的问题,它似乎随机返回 503 错误。我已经尝试使用截止日期为 600 秒的重试策略,但代码仍然返回错误。
我在具有 9.1 LTS(包括 Apache Spark 3.1.2、Scala 2.12)集群的数据 block 笔记本中使用 python3 运行此代码。
google-cloud-srtorage API 版本 -> 2.5.0
我读了一些关于这个问题的旧线程,这似乎是一个已知问题,但我仍然无法解决它。这是代码:
def blob_list(bucket_name):
try:
client = storage.Client()
blobs = client.list_blobs(bucket_name)
print('Bucket read')
return blobs
except Exception as e:
print('Counld not read the bucket', e)
b = blob_list(bucket_name)
count = 0
modified_retry = DEFAULT_RETRY.with_deadline(600)
modified_retry = modified_retry.with_delay(initial=1.5, multiplier=1.2, maximum=45.0)
for item in b:
CS = storage.Client()
blob = CS.bucket(bucket_name).blob(item.name)
blob.patch(retry=modified_retry)
# print(blob.content_encoding)
if blob.content_encoding == 'gzip' or blob.content_encoding == 'txt':
blob.content_encoding = 'csv'
blob.patch(retry=modified_retry)
count +=1
print('Changed',count,'metadata files')
代码运行时间太长,仍然抛出这个错误
调用目标函数时超过 600.0 秒的最后期限,最后一个异常:503 PATCH https://storage.googleapis.com/storage/v1/b/bucket_name/o/yof0soyd7668_2022-08-15T060000_06db87dcb5e5ee06ec13ab5fbefe4df0_be822a.csv.gz?projection=full&prettyPrint=false : 我们遇到内部错误。请重试。
错误似乎出现在 patch() 方法中。
最佳答案
不幸的是,这是 Google 方面的问题。在我每天运行 2 年多的进程中,我遇到了与您相同的 503 错误。我通过 GCP 创建了一个支持案例,正在等待回复。
关于python - PATCH 中的 google-cloud-storage 随机 503 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73409815/