Firebase管理员SDK凭据证书未验证

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

在Dialogflow中创建一个聊天机器人之后我想将它连接到我的PyCharm环境,我的最终目标是在Python中创建一个GUI并允许它通过Dialogflow后端连接,我还有一个Firestore数据库和一些API设置。

我已阅读将PyCharm连接到Dialogflow(以及Google云平台),我需要使用已通过PIP安装的Firebase-Admin SDK。

import dialogflow_v2beta1
from google.cloud import firestore
import firebase_admin
from firebase_admin import credentials


#Initialize the Admin SDK
cred = credentials.Certificate('C:Users\folder1\folder2\chatbot.json')
default_app = firebase_admin.initialize_app(cred)

#The below is a default test hoping to write a new document to the Firestore Database to check the connection works.
   doc_ref = db.collection(u'users').document(u'alovelace')
    doc_ref.set({
        u'first': u'Ada',
        u'last': u'Lovelace',
        u'born': 1815
    })

所以,有了上述内容,我只希望通过Google平台将我的环境连接到我的聊天机器人,当我运行此代码时,我希望在我的Firestore数据库中创建一些数据。

我运行上面的错误是:

C:\Users\Me\PycharmProjects\Chatbot\venv\Scripts\python.exe C:/Users/Me/PycharmProjects/Chatbot/venv/Chatbot.py
Traceback (most recent call last):
  File "C:/Users/Me/PycharmProjects/Chatbot/venv/Chatbot.py", line 12, in <module>
    cred = credentials.Certificate('C:Users\folder1\folder2\chatbot.json')
  File "C:\Users\Me\PycharmProjects\Chatbot\venv\lib\site-packages\firebase_admin\credentials.py", line 83, in __init__
    with open(cert) as json_file:
IOError: [Errno 2] No such file or directory: 'C:Users\\folder1\\folder2\\chatbot.json'

Process finished with exit code 1

简而言之,我已经检查了credentials.py文件中的第83行错误,其中默认注释表示无法找到该文件,但据我所知,这是正确的。我唯一注意到的是错误中的两个\。

任何帮助将非常感激。

更新这已经消除了这个错误,但现在又显示了另外三个:

SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

google.api_core.exceptions.PermissionDenied: 403 Missing or insufficient permissions.
python firebase pycharm dialogflow firebase-admin
4个回答
1
投票

据我所知,这条道路是错误的。应该是C:\Users\folder1\folder2\chatbot.json。在\之后你错过了C:


1
投票

解决了额外的错误;

import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

0
投票

我也有这个问题。它是由Ubuntu 14.04上的旧版Python(2.7.6)引起的。

Firebase需要在2.7.9中引入的SSLContext。我用this howto修复它。


0
投票

小心

使用这个C:/../而不是c:\ ... \

别忘了:

cred = credentials.Certificate('C:/Users/ASPIREone/PycharmProjects/amazon/tester/serviceAccountKey.json')

firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://hrd-line.firebaseio.com'
})

db = firestore.client()

doc_ref = db.collection(u'users').document(u'president')
doc_ref.set({
    u'first': u'Barrack',
    u'last': u'Obama',
    u'born': 1815
})
© www.soinside.com 2019 - 2024. All rights reserved.