0

我已经尝试了几个小时来获得 JSON 响应以将新用户推送到 Firebase 实时数据库。

from config import *
import requests
import urlopen
from firebase import firebase


# put your keys in the config.py


# Switch url for what you are doing (Enroll, verify etc)
url = "http://api.kairos.com/enroll"
firebase = firebase.FirebaseApplication(fbase, None)

payload = """
  {
    "image":"https://www.eiendomsmegler1.no/fileshare/fileupload/14933/Christer%20Hagen2.jpg?width=659&height=659&upscale=True&crop=True&x=1368&y=0&scale=0,16436991532458908",
    "subject_id": "Christer",
    "gallery_name": "MyGallery"
  }
"""


request = requests.post(url, data=payload, headers=headers)
print(request.content)


result = firebase.post('/users2', request)
print(result)

然后我得到这个 json 结果(Inn postmann)

    {
    "face_id": "b0c26c777b244fa3b1e",
    "images": [
        {
            "attributes": {
                "age": 29,
                "asian": 0.00396,
                "black": 0.00035,
                "gender": {
                    "femaleConfidence": 0,
                    "maleConfidence": 1,
                    "type": "M"
                },
                "glasses": "None",
                "hispanic": 0.00128,
                "lips": "Apart",
                "other": 0.00013,
                "white": 0.99428
            },
            "transaction": {
                "confidence": 0.99998,
                "eyeDistance": 83,
                "face_id": "b0c26c777b244fa3b1e",
                "gallery_name": "MyGallery",
                "height": 253,
                "image_id": 1,
                "pitch": 1,
                "quality": 0.95822,
                "roll": 14,
                "status": "success",
                "subject_id": "Christer",
                "timestamp": "20200725170440",
                "topLeftX": 226,
                "topLeftY": 116,
                "version": 2,
                "width": 182,
                "yaw": 0
            }
        }
    ]
}

当我尝试将其推送到 Firebase 时,我收到此错误:

TypeError: Object of type Response is not JSON serializable

有人知道我需要做什么才能将 JSON 导入 Firebase 中的新用户吗?主要目标是使用 Karios 人脸识别来登录用户。

4

1 回答 1

0

我发现出了什么问题。我需要导入 json 并使请求成为 json。

import json


result = firebase.post('/users2', request.json())
print(result)
于 2020-07-25T18:44:14.953 回答