在 Python 中使用 Firebase-Admin 解压 AuthError(例如 Dict)

Unpacking AuthError (to e.g. Dict) with Firebase-Admin in Python

我写了一个小函数来创建一个带有 firebase-admin 的用户。但是,我无法捕捉到响应,因为它采用一种奇怪的无法使用的格式。我想我必须将其格式化为字典才能提取正确的属性:

我的函数:

import firebase_admin
from firebase_admin import auth

cred   = firebase_admin.credentials.Certificate(cert_json)
app    = firebase_admin.initialize_app(cred, config)
bucket = storage.bucket(app=app)

def create_user(email):
    # Creates a new user, checks if user already exists
    try:
        return auth.create_user(email=email)
    except BaseException as e:
        return e

e 看起来如下:

我有兴趣提取 "message" 属性。我该怎么做?

Admin SDK 使用 requests 库进行 HTTP 调用。

try:
    return auth.create_user(email=email)
except auth.AuthError as e:
    req_error = e.detail # req_error is a requests.exceptions.RequestException
    response = req_error.response # response is a requests.Response
    binary_content = response.content # response content as bytes
    json_content = response.json() # parsed json representation