Firebase Firestore 客户端无法部署

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

我有一个使用 Firestore 数据库的 Firebase Cloud Functions 代码库。当我使用

firebase emulators:start
在本地模拟器中使用它时,下面的所有内容都有效,但是当我需要将其部署到 Firebase 时,我收到以下错误:

Error: User code failed to load. Cannot determine backend specification

main.py

import json
from firebase_functions import https_fn
from firebase_admin import initialize_app, firestore
import flask
from enum import Enum
from flask import g
from endpoints.moon_phase import moon_phase_bp

# Initialize Firebase app and Firestore
initialize_app()
db = firestore.client()
app = flask.Flask(__name__)


# Set up a before_request function to make db available in blueprints
@app.before_request
def before_request():
    # g.db = db
    print("before_request")

app.register_blueprint(moon_phase_bp) //Doesn't even use db, but in the future it will.


# Firebase Function to handle requests
@https_fn.on_request()
def astro(req: https_fn.Request) -> https_fn.Response:
    with app.request_context(req.environ):
        return app.full_dispatch_request()

如果我将数据库初始化更新为

db = firestore.client
,它就会部署,但显然,它是一个函数引用,因此我无法在端点中使用 Firestore 数据库。这也意味着它与我的 Firebase 凭据或项目设置无关。

这里可能出现什么问题?

python firebase google-cloud-firestore google-cloud-functions firebase-admin
1个回答
0
投票

看来您正确初始化了 firestore,我相信您已经安装了所有需要的依赖项和库。

  1. 确保您的 Firebase 设置正确并且服务帐户具有正确的权限
  2. 如果它在本地运行但不在部署中运行,请检查环境变量是否可能不同
  3. 调试日志检查 Firebase 日志以获取更详细的错误消息,您可以通过 Firebase 控制台执行此操作(有很大帮助),您可能会在其中找到帮助您推进项目的错误消息
© www.soinside.com 2019 - 2024. All rights reserved.