我正在try 使用命令firebase deploy --only functions部署FiRestore第二代功能,但收到错误:


There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
⚠  functions: Upload Error: HTTP Error: 400, Could not create bucket gcf-v2-uploads-758827227995-us-central1. 'us-central1' violates constraint 'constraints/gcp.resourceLocations'

Error: HTTP Error: 400, Could not create bucket gcf-v2-uploads-758827227995-us-central1. 'us-central1' violates constraint 'constraints/gcp.resourceLocations'

根据[文件](https://firebase.google.com/docs/functions/locations#best_practices_for_changing_region),只需使用:

exports.myStorageFunction = functions
    .region('europe-west1')
    .storage
    .object()
    .onFinalize((object) => {
      // ...
    });

我怎样才能用Python语言呢?我的函数是用Python语言编写的.

推荐答案

使用这个documentation作为引用,您可以在函数修饰器的参数中定义运行时选项.如果要try 为用Python编写的Firebase Cloud函数设置区域,可以try 在函数修饰器中指定区域,如下所示:

from firebase_functions import https_fn

@https_fn.on_request(region='asia-east1')
# @https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
    return https_fn.Response("Hello world!")

如果您正在配置云FiRestore触发器(例如on_document_created),它将如下所示:

from firebase_functions.firestore_fn import (
    on_document_created,
    Event,
    DocumentSnapshot,
)


@on_document_created(document="users/{userId}", region="asia-east1")
def userCreated(event: Event[DocumentSnapshot]) -> None:
    new_value = event.data.to_dict()
    name = new_value["name"]
    print(name)

Python-3.x相关问答推荐

Python gpsd客户端

按一列分组,如果日期列相同,则在数字列中填写缺少的值

如何将值映射到具有上限和下限的新列

PyQt5 中耦合滑块和拨号小部件.解决结果不一致的问题

Python - 根据条件附加 NULL 值

从 LeetCode 的 Python 解决方案类中理解关键字 self

提高时间复杂度的一些建议

裁剪复数以解决 exp 中的溢出错误

Pandas 按值和索引对 DF 进行排序

找到操作系统的图片文件夹的 CLI

有效地缩短列表,直到第一次和最后一次出现不同于 None 的值

段落中句子的索引

机器学习实验笔记本的工作区 url

python中两个连续的yield语句如何工作?

参数化泛型不能与类或实例判断一起使用

创建日志(log)文件

从大字典中弹出 N 项的最快方法

如何在继承的数据类中创建可选字段?

python - 使用 matplotlib 和 boto 将绘图从内存上传到 s3

TypeError: write() 参数必须是 str,而不是字节(Python 3 vs Python 2)