Python 2.7 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 Python 2.7 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 Python 2.7 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 Python 版本。
Cloud Storage 错误和错误处理
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用 App Engine 的 UrlFetch
功能,您可以访问 Google Cloud Storage。因此,可能存在的错误有三种:
- App Engine UrlFetch 暂时性错误。
- Google Cloud Storage 暂时性错误。
- 与存储分区和对象授权相关的 Google Cloud Storage 错误。
适用于 Cloud Storage 的 App Engine 客户端库会自动处理 App Engine 端和 Google Cloud Storage 端的超时错误并执行重试,因此您无需为应用添加逻辑来处理此问题。您可以通过 RetryParams 类公开超时和重试机制的配置,该类可用于更改任意或全部默认设置。通过该函数的 retry_params
参数,您可以将更改应用于所有函数调用或为特定调用指定更改。
错误
适用于 Cloud Storage 的 App Engine 客户端库定义了以下错误异常类:
- cloudstorage.Error
-
此包中所有异常的基类。错误既可能产生自 App Engine ,也可能产生自 Google Cloud Storage。如需详细了解来自 Google Cloud Storage 的 HTTP 错误代码,请参阅 Google Cloud Storage 文档中的 HTTP 状态和错误代码。
- cloudstorage.AuthorizationError
- Google Cloud Storage 收到未经授权的请求。如果已获授权的应用使用的访问令牌已过期,则会发生此错误。通常,此错误会在适用于 Cloud Storage 的 App Engine 客户端库中自动处理,该客户端库会获取新的访问令牌并重试请求。
- cloudstorage.ForbiddenError
此错误 (403) 表示用户未获得 Google Cloud Storage 的授权,无法发出请求。
- cloudstorage.NotFoundError
- HTTP 错误 404。该错误表示您在对
cloudstorage.delete()
、cloudstorage.listbucket()
、cloudstorage.open()
或 cloudstorage.stat()
的调用中指定的存储分区或对象不存在。
- cloudstorage.TimeoutError
- 如果尝试连接 Google Cloud Storage 服务器超时,重试后仍失败,则会引发此错误。如需了解如何更改默认超时处理和重试,请参阅 RetryParams。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-20。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\u003cp\u003eThe App Engine client library for Cloud Storage handles timeout errors and retries automatically, eliminating the need for manual handling in your app.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRetryParams\u003c/code\u003e class allows customization of timeout and retry settings, which can be applied globally or to specific function calls.\u003c/p\u003e\n"],["\u003cp\u003eErrors related to Google Cloud Storage access can stem from transient issues, or from bucket and object authorization, in addition to transient errors coming from App Engine \u003ccode\u003eUrlFetch\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecloudstorage\u003c/code\u003e library defines exception classes like \u003ccode\u003eError\u003c/code\u003e, \u003ccode\u003eAuthorizationError\u003c/code\u003e, \u003ccode\u003eForbiddenError\u003c/code\u003e, \u003ccode\u003eNotFoundError\u003c/code\u003e, and \u003ccode\u003eTimeoutError\u003c/code\u003e to handle various error scenarios.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eForbiddenError\u003c/code\u003e (403) is common when the bucket permissions (bucket ACL) are not configured properly to allow access from the application.\u003c/p\u003e\n"]]],[],null,[]]