TypeError: Object of type 'Tag' is not JSON serializable

Viewed 26726

I am trying to create a JSON object and send it to the Firebase Database using python, but when I do this I get:

TypeError: Object of type 'Tag' is not JSON serializable

Here is my code:

data = {'address': address,
    'name': name
   }

print(type(data))
sent = json.dumps(data)
result = firebase.post("/tHouse/houseTest", sent)  

The is something wrong with json.dumps(data) since the error is pointed out here. Running print(type(data)) returns though <class 'dict'>.

Also the name and address are set beforehand

2 Answers

You can convert data by looping through found items and finding what attribute you are looking for.

For example, if we have a list (with TAG's) of images. We can loop through it and create a list where we would append-only strings with URL's.

final = []
for i in images:
    image = i.attrs['src']
    final.append(image)
Related