【问题标题】:Python , Raspberry pi, Firestore project IDPython 、树莓派、Firestore 项目 ID
【发布时间】:2018-04-06 11:24:35
【问题描述】:

我正在尝试从我的 Raspberry pi 3 使用 firestore 文档中给出的代码连接到我的 firestore 数据库,但示例代码说必须在环境变量中设置数据库的项目 ID,而我不是能做到。。 代码:

from google.cloud import firestore
import google.cloud.exceptions


def quickstart_new_instance():
    # [START quickstart_new_instance]
    from google.cloud import firestore

    # Project ID is determined by the GCLOUD_PROJECT environment variable
    db = firestore.Client()
    # [END quickstart_new_instance]

    return db

sn-p 链接:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/firestore/cloud-client/snippets.py

【问题讨论】:

  • 为什么不能设置环境变量?
  • 我不知道该怎么做...你能告诉我如何将 firestore 数据库 ID 添加为 Raspberry pi 环境变量吗??
  • 我自己从未这样做过,但这里似乎有一些不错的选择:google.com/search?q=raspberry+pi+set+environment+variable 你尝试过类似的方法吗?

标签: python google-cloud-firestore raspberry-pi3


【解决方案1】:

您可能希望在操作系统级别设置环境变量,但您可以在代码中这样做:

from google.cloud import firestore
import google.cloud.exceptions

def quickstart_new_instance():
    # [START quickstart_new_instance]
    from google.cloud import firestore

    # Set GCLOUD_PROJECT environment variable
    os.environ["GCLOUD_PROJECT"] = "1234"

    # Project ID is determined by the GCLOUD_PROJECT environment variable
    db = firestore.Client()
    # [END quickstart_new_instance]

    return db

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2015-10-14
    • 2014-09-20
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多