0

I have tried for a few hours to get a JSON response to push a new user to a Firebase realtime database.

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)

I then get this json result (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
            }
        }
    ]
}

When I try to push it to Firebase I get this error :

TypeError: Object of type Response is not JSON serializable

Does anybody know what I need to do to get the JSON into the new user in Firebase? The main goal is use Karios face recognition to log in a user.

Chagen
  • 45
  • 1
  • 1
  • 8

1 Answers1

0

I found out what was wrong. I needed to import json and make the request a json.

import json


result = firebase.post('/users2', request.json())
print(result)
Chagen
  • 45
  • 1
  • 1
  • 8