Python 2.7 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 Python 2.7 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 Python 2.7 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 Python 版本。
例外情况
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
注意:强烈建议构建新应用的开发者使用 NDB 客户端库,它与 DB 客户端库相比具有多项优势,例如可通过 Memcache API 进行自动实体缓存。如果您当前使用的是较早的 DB 客户端库,请参阅 DB 到 NDB 的迁移指南
google.appengine.ext.db
包提供以下异常类:
- exception Error()
-
这是该包中所有异常的基类。
- exception BadArgumentError()
- 提供给查询方法的参数错误。
- exception BadFilterError()
- 查询中的过滤器字符串无效。
- exception BadKeyError()
- 提供的键字符串是无效的键。
- exception BadPropertyError()
- 无法创建属性,因为其名称不是字符串。
- exception BadQueryError()
- 查询字符串是无效的查询。
- exception BadRequestError()
- 对数据存储区服务的请求有一个或多个无效属性。如果 Model 的某个子类使用不正确的实现替换某些方法(例如 kind()),则可能出现这种情况。
- exception BadValueError()
- 无法为属性分配值,因为该值对于该属性类型无效。
- exception ConfigurationError()
- 属性配置错误。
- exception DuplicatePropertyError()
- Model 定义有多个名称相同的属性。
- exception InternalError()
- 数据存储区服务发生内部错误。此异常并不一定意味着操作失败。
- exception KindError()
- 应用尝试将数据实体与不匹配该实体的 Model 类配合使用。
- exception NeedIndexError()
- 在 SDK 无法为需要索引的查询找到匹配的索引时引发。检查管理控制台以管理索引和 index.yaml 文件。
- exception NotSavedError()
- 执行了一个需要将对象保存(放置)到数据存储区中的操作,但对象未保存。
- exception PropertyError()
- 引用的模型属性在数据对象上不存在。
- exception ReferencePropertyResolveError()
- ReferenceProperty 引用的模型不存在。请参阅参考。
- exception ReservedWordError()
- 模型定义了名称禁止使用的属性。请参阅禁止使用的属性名称。
- exception Rollback()
- 表示事务中的函数需要回滚事务,而不是提交事务。事务中未捕获的异常将导致该事务回滚。当某个函数要回滚且没有其他异常适用时,则该异常类可提供方便。
- exception Timeout()
- 数据存储区操作超出允许的最大数据存储区操作时间时引发。此异常并不一定意味着操作失败。
- exception TransactionFailedError()
- 即使在重试后,也无法提交事务或数据存储区操作。这通常由高争用率引起:许多其他应用实例同时更新数据,且该实例无法在固定的重试次数内提交其事务。请参阅事务。
google.appengine.runtime.apiproxy_errors
包提供以下异常类:
- exception CapabilityDisabledError()
-
表示未执行数据存储区 API 调用,因为该特定数据存储区功能不可用。
如未另行说明,那么本页面中的内容已根据知识共享署名 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\u003eDevelopers are highly recommended to utilize the NDB Client Library for new applications due to its enhanced features like automatic entity caching.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.ext.db\u003c/code\u003e package offers a range of exception classes to handle various errors related to datastore operations, including issues with arguments, filters, keys, properties, and queries.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.runtime.apiproxy_errors\u003c/code\u003e package includes the \u003ccode\u003eCapabilityDisabledError\u003c/code\u003e exception, which signals when a specific datastore functionality is not accessible.\u003c/p\u003e\n"],["\u003cp\u003eSeveral exceptions in \u003ccode\u003egoogle.appengine.ext.db\u003c/code\u003e highlight potential issues in model definition and data consistency, such as \u003ccode\u003eDuplicatePropertyError\u003c/code\u003e, \u003ccode\u003eKindError\u003c/code\u003e, \u003ccode\u003ePropertyError\u003c/code\u003e, \u003ccode\u003eReferencePropertyResolveError\u003c/code\u003e, and \u003ccode\u003eReservedWordError\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe package provides specific error handling for transaction-related issues with classes like \u003ccode\u003eRollback\u003c/code\u003e, and \u003ccode\u003eTransactionFailedError\u003c/code\u003e to help in situations where a transaction needs to be rolled back, or a transaction could not be committed.\u003c/p\u003e\n"]]],[],null,["# Exceptions\n\n**Note:**\nDevelopers building new applications are **strongly encouraged** to use the\n[NDB Client Library](/appengine/docs/legacy/standard/python/ndb), which has several benefits\ncompared to this client library, such as automatic entity caching via the Memcache\nAPI. If you are currently using the older DB Client Library, read the\n[DB to NDB Migration Guide](/appengine/docs/legacy/standard/python/ndb/db_to_ndb)\n\nThe `google.appengine.ext.db` package provides the following exception classes:\n\nexception Error()\n\n: This is the base class for all exceptions in this package.\n\nexception BadArgumentError()\n: A bad argument was given to a query method.\n\nexception BadFilterError()\n: A filter string in the query is invalid.\n\nexception BadKeyError()\n: The provided key string is not a valid key.\n\nexception BadPropertyError()\n: The property could not be created because its name is not a string.\n\nexception BadQueryError()\n: The query string is not a valid query.\n\nexception BadRequestError()\n: The request to the datastore service has one or more invalid properties. This is possible if a subclass of [Model](/appengine/docs/legacy/standard/python/datastore/modelclass) overrides some methods (such as [kind()](/appengine/docs/legacy/standard/python/datastore/modelclass#Model_kind)) with an incorrect implementation.\n\nexception BadValueError()\n: The property could not be assigned a value because the value is invalid for the property type.\n\nexception ConfigurationError()\n: A property is not configured correctly.\n\nexception DuplicatePropertyError()\n: A model definition has more than one property with the same name.\n\nexception InternalError()\n: There was an error internal to the datastore service. This exception does not necessarily mean that the operation failed.\n\nexception KindError()\n: The application attempted to use a data entity with a model class that does not match the entity.\n\nexception NeedIndexError()\n: Raised when the SDK does not find a matching index for a query that requires one. Check the [Administration Console](/appengine/docs/adminconsole) to manage your indexes and your [index.yaml](/appengine/docs/legacy/standard/python/config/indexconfig#creating_datastore_indexes) file.\n\nexception NotSavedError()\n: An action was performed that requires the object to have been saved (put) to the datastore, but the object is not saved.\n\nexception PropertyError()\n: The referenced model property does not exist on the data object.\n\nexception ReferencePropertyResolveError()\n: The model referenced by a [ReferenceProperty](/appengine/docs/legacy/standard/python/datastore/typesandpropertyclasses#ReferenceProperty) does not exist. See [References](/appengine/docs/legacy/standard/python/datastore/datamodeling#References).\n\nexception ReservedWordError()\n: A model defines a property whose name is disallowed. See [Disallowed Property Names](/appengine/docs/legacy/standard/python/datastore/modelclass#Disallowed_Property_Names).\n\nexception Rollback()\n: Indicates that a function in a transaction wants to roll back the transaction instead of committing it. Any uncaught exception in a transaction will cause the transaction to roll back. This exception class is for convenience, when a function wants to roll back and no other exception applies.\n\nexception Timeout()\n: Raised when the datastore operation exceeds the maximum amount of time allowed for datastore operations. This exception does not necessarily mean that the operation failed.\n\nexception TransactionFailedError()\n: The transaction or datastore operation could not be committed, even after retrying. This is usually caused by a high rate of contention: The data is being updated by many other application instances simultaneously, and this instance could not commit its transaction within a fixed number of retries. See [Transactions](/appengine/docs/legacy/standard/python/datastore/transactions).\n\nThe `google.appengine.runtime.apiproxy_errors` package provides the following exception classes:\n\nexception CapabilityDisabledError()\n\n: Indicates that a datastore api call was not performed as that particular datastore functionality is not available."]]