POST data to Firebase using Python

13,935

Solution 1

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)

Solution 2

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)
Share:
13,935
MoreScratch
Author by

MoreScratch

I know just enough to be dangerous. I break more things than I fix.

Updated on June 12, 2022

Comments

  • MoreScratch
    MoreScratch about 2 years

    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?