繁体   English   中英

'默认的 Firebase 应用不存在。 确保通过调用 initialize_app()' 初始化 SDK

[英]'The default Firebase app does not exist. Make sure to initialize the SDK by calling initialize_app()'

我正在尝试使用用于数据存储的 Firebase 实时数据库制作一个 python discord 机器人。 我在脚本开头初始化应用程序,但是,当我尝试创建引用时,出现错误The default Firebase app does not exist. Make sure to initialize the SDK by calling initialize_app() The default Firebase app does not exist. Make sure to initialize the SDK by calling initialize_app() 我不知道为什么会这样,因为我初始化了它? 一些代码示例:

### I initialise the firebase app here?
# Variable def
client = commands.Bot(command_prefix=">", help_command=None)
slash = SlashCommand(client, sync_commands=True)
token = os.environ['TOKEN']
BotGuilds = [916737523017986079]
cred_obj = firebase_admin.credentials.Certificate('rtdb-key.json')
firebase_admin.initialize_app(cred_obj, {
  'databaseURL':'https://datastoretuu-default-rtdb.firebaseio.com/'
    }, f"main_bot")
### Cause of error
async def info(ctx: SlashContext, player: str=None):
  if player is None:
    player = ctx.author.nick


  tuu_logo = get(ctx.guild.emojis, name="tuu")
  pm_logo = get(ctx.guild.emojis, name="pm")
  roblox_logo = get(ctx.guild.emojis, name="roblox")
  discord_logo = get(ctx.guild.emojis, name="discord")

  apiresponse = requests.get(f"https://api.roblox.com/users/get-by-username?username={player}").json()
  playerid = apiresponse['Id']
  current_ref = db.reference(f"TUUPointStorage/{playerid}/Points")
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Error is here
  result = current_ref.get()

非常感谢您的帮助!

事实证明,如果您不给应用程序命名,它将再次开始工作。 感谢 MatsLindh 的回答。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM