While coding in python in many projects, I’ve encountered the error of firebase’s RealTime Database sending an integer instead of the json file. I’ve checked and I’ve imported the JSON packages, loaded the correct files (etc)
Here is the following code:
data = os.open('data/character.json', os.O_RDONLY)
data_send = firebase.post('/', data)
I’ve setup and ran everything in the database and it is connected. However, if you run this snippet of code, it returns simply: 4 as shown in the photo below.
The file character.json is in correct json format:
{
"username": "admin",
"gender": "male",
}
I do not see where “4” comes from and it is not intended. Does anyone know how this works?
CodePudding user response:
Your data
variable does not contain the file contents, but it merely a handle to that file. The 4 that you're sending is the numeric handle of the file.
If you want to send the data from the file, you'll have to read that into your Python code (e.g. Read from file and write to another python), and then send the data in the format you want to the database.