【问题标题】:How can I obtain programatically the location prefix of an App Engine project ID?如何以编程方式获取 App Engine 项目 ID 的位置前缀?
【发布时间】:2020-04-17 12:24:27
【问题描述】:

我在 python 3.7 中使用 Google App Engine 标准,需要使用其密钥获取数据存储区中实体的旧版安全 URL。

为了实现这一点,我需要知道 location_prefix。

https://googleapis.dev/python/datastore/latest/_modules/google/cloud/datastore/key.html#Key.to_legacy_urlsafe

如何在 Python 中以编程方式获取给定项目 ID 的值?

【问题讨论】:

    标签: google-app-engine google-app-engine-python


    【解决方案1】:

    这是你要找的吗?:Retrieving Entities from Keys

    appengine/standard/ndb/entities/snippets.pyView on GitHub

    您还可以使用实体的密钥来获取适合的编码字符串 用于嵌入 URL:

    url_string = sandy_key.urlsafe()
    

    这会产生类似“agVoZWxsb3IPCxIHQWNjb3VudBiZiwIM”的结果,以后可以使用它来重建密钥并检索原始实体:

    sandy_key = ndb.Key(urlsafe=url_string)
    sandy = sandy_key.get()
    

    【讨论】:

    • 很遗憾,除非您提供 location_prefix,否则您要获取的旧版 url 将不正确。
    猜你喜欢
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 2016-02-03
    • 2019-10-14
    • 1970-01-01
    • 2022-09-27
    相关资源
    最近更新 更多