Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST data to Firebase using Python

I am using python-firebase and can't seem to get data to POST properly. Whatever I send is POSTED to firebase but the entities are not viewable in the dashboard as JSON. Here is my code:

json = '{ url: "' + url + '" address: "' + address + '" name: "' + name + '"}'
result = firebase.post("/businesses", json )

In the Dashboard for a POSTED entity I see:

enter image description here

Any idea on how I can get the entities to POST properly?

like image 922
MoreScratch Avatar asked Mar 29 '16 00:03

MoreScratch


People also ask

How do I insert data into Firebase using python?

Insert record in firebaseImport library of Firebase in Python script. Then, create database connection using the below command. FirebaseApplication takes two parameters; one is URL of database and second is authentication details for database. But we don't have any rules so we are passing None.

Can you use python with Firebase?

We currently support Python 3.7+. Firebase Admin Python SDK is also tested on PyPy and Google App Engine environments.


2 Answers

Your JSON keys need to be strings in quotes. There are also no commas in your JSON string. Neatest way is to use the json library:

import json

# your variables are already assigned before this
data = {'url': url, 'address': address, 'name': name}
sent = json.dumps(data)
result = firebase.post("/businesses", sent)
like image 73
SoreDakeNoKoto Avatar answered Oct 12 '22 14:10

SoreDakeNoKoto


Your JSON is not valid (no commas between dict entries) but you can post a normal dict instead of a JSON string anyway:

data = {'url': url, 
        'address': address,
        'name': name}
result = firebase.post("/businesses", data)
like image 38
Selcuk Avatar answered Oct 12 '22 14:10

Selcuk