gpt4 book ai didi

Python 谷歌云功能连接由同行重置

转载 作者:太空狗 更新时间:2023-10-29 20:26:57 25 4
gpt4 key购买 nike

详见此处:https://issuetracker.google.com/issues/113672049

在这里交叉发布:https://github.com/GoogleCloudPlatform/google-cloud-python/issues/5879 )

在 Python 中从 Google Cloud Functions 使用 Firebase Storage API 时出现连接重置错误。

部署的函数正在调用一个 blob-get,即

from firebase_admin import storage

def fn(request):
bucket = 'my-firebase-bucket'
path = '/thing'
blob = storage.bucket(bucket).get_blob(path)

故障是间歇性的;该功能的成功率约为 90%。

函数部署后第一次调用似乎更容易失败。

最佳答案

云函数是无状态的,但可以重用之前调用的全局状态。这在 tips 中有解释。和 these docs .

使用带重试的全局状态应该会给你一个更强大的功能:

from tenacity import retry, stop_after_attempt, wait_random
from firebase_admin import storage

@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_bucket(storage):
return storage.bucket('my-firebase-bucket')

@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_blob(bucket, path):
return bucket.get_blob(path)

bucket = get_bucket(storage)

def fn(request):
path = '/thing'
blob = get_blob(bucket, path)
# etc..

关于Python 谷歌云功能连接由同行重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52129628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com