Firebase Admin SDK凭证证书无法验证

时间:2018-07-26 09:05:48

标签: python firebase pycharm dialogflow firebase-admin

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

我已阅读将PyCharm连接到Dialogflow(以及Google Cloud平台),我需要使用通过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

简而言之,我已经检查了certificate.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.

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

解决了其他错误;

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

答案 2 :(得分:0)

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

Firebase需要2.7.9中引入的SSLContext。我使用this howto进行了修复。

答案 3 :(得分: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
})