gpt4 book ai didi

python - 检查某个 key 是否是当前应用程序 ID 的有效 key

转载 作者:行者123 更新时间:2023-12-01 05:01:00 25 4
gpt4 key购买 nike

有没有办法或函数来检查 key 是否是当前应用程序 ID 的有效 key ?

例如

key = fetch_urlsafe_key_from_external_source()
key = ndb.Key(urlsafe=key)
if not is_valid_key(key):
return
# do something with the key

编辑:目前我正在做

def is_valid_key(key):
try:
key.get()
except datastore_errors.BadRequestError:
return False
return True

但希望有人提出一些不需要访问数据存储的建议

最佳答案

您可以检查 key 中包含的应用程序 ID 是否正确:

import os

def is_valid_key(key):
"""Valid key should include an ID and current application ID.
"""
if key.app() == os.getenv('APPLICATION_ID') and key.id():
return True
return False

关于python - 检查某个 key 是否是当前应用程序 ID 的有效 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26233350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com