使用Firebase Admin SDK和Python的身份验证错误

问题描述 投票:1回答:1

我正在尝试将Firebase与用于Python(https://firebase.google.com/docs/database/admin/start)的官方Admin SDK进行接口。

但是,我做错了,因为我没有获得授权,所以>

这是我的代码:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

# Fetch the service account key JSON file contents
cred = credentials.Certificate('./ServiceAccountKey.json')

# Initialize the app with a None auth variable, limiting the server's access
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://*[database name]*.firebaseio.com',
    'databaseAuthVariableOverride': None
})

# The app only has access to public data as defined in the Security Rules
ref = db.reference('/public_resource')
print(ref.get())

这是我得到的错误:

python3 firebase_test.py 
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/firebase_admin/db.py", line 943, in request
    return super(_Client, self).request(method, url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/firebase_admin/_http_client.py", line 117, in request
    resp.raise_for_status()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://*[database name]*.firebaseio.com/public_resource.json?auth_variable_override=null

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "firebase_test.py", line 16, in <module>
    print(ref.get())
  File "/usr/local/lib/python3.6/site-packages/firebase_admin/db.py", line 222, in get
    return self._client.body('get', self._add_suffix(), params=params)
  File "/usr/local/lib/python3.6/site-packages/firebase_admin/_http_client.py", line 129, in body
    resp = self.request(method, url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/firebase_admin/db.py", line 945, in request
    raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.UnauthenticatedError: Unauthorized request.

我正在使用已安装Python 3.6的Raspberry Pi 4 B。

有人可以指出为什么发生这种情况以及如何解决它的正确方向吗?

我正在尝试将Firebase与用于Python的官方Admin SDK(https://firebase.google.com/docs/database/admin/start)连接。但是,我做错了,因为我没有以某种方式得到授权...

python firebase sdk admin
1个回答
0
投票

发现了!

© www.soinside.com 2019 - 2024. All rights reserved.