python-3.x - 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)
解决方案
推荐阅读
- oracle - oracle如何找到阻塞的sql
- rest - Dart - 获取 POST 后从服务器上的 HttpRequest 读取正文的问题
- java - Weblogic:使用组合密钥库来侦听具有多个 MDB 的不同 SSL 远程服务器响应队列?
- recursion - 如何制作树状结构,其中节点是 Rust 中的特征对象?
- git - 功能分支合并到开发时的 GIT 更改列表创建问题
- python - Json 文件作为列表而不是字典加载。使用蟒蛇
- javascript - Shiny R中的父/子行,具有可变行数的单个数据框
- oracle - 使用 ora2pg 工具从 oracle 中值为 0 的 CLOB 列中提取数据到 postgresql
- python - Python Excel电子表格阅读
- r - 在R中使用逻辑条件的ifelse语句