如何在 python3 ndb 中将新密钥转换为旧密钥

问题描述 投票:0回答:1

这是我的代码

  new_key= ndb.Key(urlsafe = request.user_key)

这是用 python3 ndb 编写的 这将返回我们的密钥,我们在 urlsafe 中进行更改

key = new_key.urlsafe()
key.decode(encoding="utf-8")

但这不是返回给我们与 python2 密钥不匹配的新密钥

现在谷歌应用程序引擎已经改变而不是运动python2,但他们给了我们这个方法

to_old_key

但这不起作用

https://googleapis.dev/python/python-ndb/latest/key.html https://googleapis.dev/python/python-ndb/latest/_modules/google/cloud/ndb/key.html#Key.to_old_key

我们如何使用这个

python python-3.x python-2.7 google-app-engine ndb
1个回答
0
投票
  1. 您所要求的内容无法通过 cloud ndb 实现/支持。根据您链接到的文档,该方法

加薪: NotImplementedError:总是。

因此,如果您使用的是云ndb,该方法总是会引发错误。该文档将您指向 from_old_key,了解其不受支持的原因。

old_key 应该是 google.appengine.ext.db.Key(其中 是 google.appengine.api.datastore_types.Key 的别名)。

但是,google.appengine.ext.db 模块是旧版模块的一部分 Google App Engine 运行时,一般不可用。

  1. 您应该尝试捆绑的 API,即 google.appengine.ext.ndb。我仍然可以在代码中看到方法,并且它被设置为返回有效值
© www.soinside.com 2019 - 2024. All rights reserved.