简体   繁体   English

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

[英]Firebase Admin SDK credentials certificate not validating

After creating a chatbot in Dialogflow I want to connect this to my PyCharm environment, my end goal is to create a GUI within Python and allow it to connect through Dialogflow back-end, I also have a Firestore database and a few API's set up.在 Dialogflow 中创建聊天机器人后,我想将其连接到我的 PyCharm 环境,我的最终目标是在 Python 中创建一个 GUI 并允许它通过 Dialogflow 后端连接,我还有一个 Firestore 数据库和一些 API 设置。

I have read to connect PyCharm to the Dialogflow (and, the Google Cloud platform) I need to use the Firebase-Admin SDK, which has been installed through PIP.我已阅读将 PyCharm 连接到 Dialogflow(以及 Google Cloud 平台)我需要使用 Firebase-Admin SDK,它已通过 PIP 安装。

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
    })

So, with the above I simply hope to connect my environment to my chatbot through the Google platform and when I run this code I hope for some data to be created in my Firestore database.因此,通过以上内容,我只是希望通过 Google 平台将我的环境连接到我的聊天机器人,并且当我运行此代码时,我希望在我的 Firestore 数据库中创建一些数据。

The error I get when I run the above is:运行上面的错误是:

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

In short, I've checked the line 83 error in the credentials.py file where the default comment suggests means the file can't be found, but is correct as far as I can tell.简而言之,我检查了 credentials.py 文件中的第 83 行错误,其中默认注释表明找不到该文件,但据我所知是正确的。 The only thing I notice are the two \ in the error.我唯一注意到的是错误中的两个 \ 。

Any help would be much appreciated.任何帮助将非常感激。

UPDATE This has erased that error, but now being shown another three:更新这已经消除了那个错误,但现在显示另外三个:

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.

That path is wrong as far as I can tell. 据我所知,这条道路是错误的。 Should be C:\\Users\\folder1\\folder2\\chatbot.json . 应该是C:\\Users\\folder1\\folder2\\chatbot.json You're missing \\ after C: . 您在C:之后缺少\\

Solved the additional errors by; 解决了其他错误;

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

I had this problem too. 我也有这个问题。 It was caused by an old Python version (2.7.6) on Ubuntu 14.04. 这是由Ubuntu 14.04上的旧Python版本(2.7.6)引起的。

Firebase requires SSLContext which was introduced in 2.7.9. Firebase需要在2.7.9中引入的SSLContext。 I fixed it using this howto . 我使用此方法来修复它。

be careful 小心

use this C:/../ instead c:\\ ... \\ 使用此C:/../代替c:\\ ... \\

don't forget: 不要忘记:

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
})

I got the same error (MAC USER)我得到了同样的错误(MAC 用户)

Code fb_test.py代码 fb_test.py

import firebase_admin
from  firebase_admin import db
from firebase_admin import credentials

cred = credentials.Certificate("<dir>cred.json")
firebase_admin.initialize_app(cred, {'databaseURL':'https://<URL>'})

I ended adding the verify=False parameter on /Users//.pyenv/versions/3.9.11/lib/python3.9/site-packages/google/auth/transport/requests.py我结束了在 /Users//.pyenv/versions/3.9.11/lib/python3.9/site-packages/google/auth/transport/requests.py 上添加verify=False参数

response = self.session.request(method, url, data=body, headers=headers, 
timeout=timeout, verify=False, **kwargs)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM