5

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?

2 Answers 2

6

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)
Sign up to request clarification or add additional context in comments.

1 Comment

How do you get the document id of the above added document?
5

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.