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-09-04。
[[["易于理解","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-09-04。"],[[["\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,["# Cloud Storage Errors and Error Handling\n\nGoogle Cloud Storage is accessed by the App Engine ` UrlFetch ` feature. As a result,\nthere are three sources of possible errors:\n\n- App Engine UrlFetch transient errors.\n- Google Cloud Storage transient errors.\n- Google Cloud Storage errors related to buckets and object authorization.\n\nThe App Engine client library for Cloud Storage handles timeout errors on both the App Engine side and\nthe Google Cloud Storage side and performs retries automatically, so your app does not need to\nadd logic to handle this. The configuration of the timeout and retry mechanism\nis exposed through the [RetryParams](/appengine/docs/legacy/standard/python/googlecloudstorageclient/retryparams_class)\nclass, which you can use to change any or all of the default settings. You can\nmake your changes to apply to all function calls or you can specify changes for\na specific call using the function's `retry_params` parameter.\n\nErrors\n------\n\nThe App Engine client library for Cloud Storage has the following error exception classes defined:\n\ncloudstorage.Error\n\n: The base class for all exceptions in this package. Errors can be\n generated from App Engine or from Google Cloud Storage. For details on HTTP\n error codes from Google Cloud Storage, see\n [HTTP Status and Error\n Codes](/storage/docs/reference-status#standardcodes) in the Google Cloud Storage documentation.\n\ncloudstorage.AuthorizationError\n: An unauthorized request was received by Google Cloud Storage. This error can occur if an\n authorized app is using an access token that has expired. Normally, this error\n is handled automatically in the App Engine client library for Cloud Storage, which gets a new access token\n and retries the request.\n\ncloudstorage.ForbiddenError\n\n: This error (403) indicates that the user was not authorized by Google Cloud Storage to\n make the request.\n\n - The various possible causes for this error are listed in the [Google Cloud Storage error\n documentation](/storage/docs/reference-status#standardcodes) for **403-Forbidden**.\n - A common source of this error is that the bucket permissions (bucket ACL) are not set properly to allow your app access. See [Google Cloud Storage Authentication](/storage/docs/authentication) for information on setting up access.\n\n \u003cbr /\u003e\n\ncloudstorage.NotFoundError\n:\n HTTP error 404. The bucket or object you specified in a call to\n `cloudstorage.delete()`, `cloudstorage.listbucket()`,\n `cloudstorage.open()`,\n or `cloudstorage.stat()` does not exist.\n\ncloudstorage.TimeoutError\n:\n This error is raised when the attempt to contact Google Cloud Storage servers times out even\n after retry attempts. (See\n [RetryParams](/appengine/docs/legacy/standard/python/googlecloudstorageclient/retryparams_class)\n for information on changing the default timeout handling and retries."]]