首页 > 解决方案 > ZONE_RESOURCE_POOL_EXHAUSTED 是 googleapiclient.errors.httpError 吗?

问题描述

我正在使用 googleapiclient(Python) API,如 images().get()、images().insert() 等来列出图像、创建 VM 实例等

上个月来自谷歌云的几个 ZONE_RESOURCE_POOL_EXHAUSTED 错误导致我的代码出现以下异常

Exception: {'errors': [{'code': 'ZONE_RESOURCE_POOL_EXHAUSTED',     'message': "The zone 'projects/<project-name>/zones/us-central1-b' does not have enough resources available to fulfill the request.  Try a different zone, or try again later."}]}

我想通过从我的服务器向客户端发送一个唯一的错误代码来处理我的代码中的这个错误,以便在一段时间后重试这个请求,因为错误是暂时的。

出于同样的原因,我无法故意重现此错误......它的瞬态

我在 GitHub 上检查了 googleapi 代码https://github.com/googleapis/google-api-python-client 但找不到 ZONE_RESOURCE_POOL_EXHAUSTED 我需要验证它是否是“HttpError”类型的异常或其他类然后可以在我的代码中处理它

我已经在我的代码中处理类型为 googleapiclient.errors.HttpError 的异常,方法是打印一条错误消息并将其提升为 urllib.error.HTTPError (服务器将这种情况下的代码 e.resp['status'] 发送给客户端)

except HttpError as e:
    printf('Failed to create %s: %s\n', instanceName,   
            e._get_reason())
    raise HTTPError(
            None, int(e.resp['status']), e._get_reason(), "", None)

标签: python-3.xgoogle-cloud-platformgoogle-api-client

解决方案


推荐阅读