Python中无法访问Firestore非默认数据库的问题求助
Python中无法访问Firestore非默认数据库的问题求助
我现在碰到了个棘手的问题:没办法访问Google Firestore里除了(default)之外的数据库。之前我查了网上的各种解决方案,尝试在凭证配置里加上databaseId参数,但根本没用,情况还是老样子。
下面是我当前的代码:
def firestore_add_doc(data): print('DEBUG Firestore document creation script triggered') # Load credentials from dictionary cred = credentials.Certificate(cred_dict) # Firestore collection name (must exist) FIRESTORE_COLLECTION = "firestore_collection_one" try: # Check if Firebase is already initialized if not firebase_admin._apps: firebase_admin.initialize_app(cred, { 'projectId': 'cheftest-f174c', 'databaseId': 'cheftestfirestore' }) else: print("Firebase already initialized.") # Get Firestore client db = firestore.client() # Add document to Firestore collection_ref = db.collection(FIRESTORE_COLLECTION) doc_ref = collection_ref.add(data) print(f"Document added with ID: {doc_ref[1].id}") except Exception as e: print(f"Error adding document to Firestore: {e}") if __name__ == "__main__": data = { "key1test": "value1test", "key2test": "value2test" } firestore_add_doc(data)
现在代码依然只会把数据写入(default)数据库,如果这个默认数据库不存在的话,就直接抛出错误。我已经通过Google CLI确认过,那个我想访问的非默认数据库确实是存在的,可就是没法往里写数据,有没有大佬能帮忙看看问题出在哪?
备注:内容来源于stack exchange,提问作者tom
相关产品推荐
相关产品推荐

