- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey!
I am trying to write a code for a server in Python and I got stuck.
I gave as an input a csv file and using pandas we get a dictionary where the titles are the keys and the inputs are the values.
From that we get the below :
I have written the below endpoint to get all the islands that belog to the specific municipality :
and the function I have used is the below one :
but I get an error, I suppose that the error relates to the type of my return. I return an array of dictionaries, right? Is that not allowed? The error that I get is "TypeError: Object of type int64 is not JSON serializable".
:unsure:
I am trying to write a code for a server in Python and I got stuck.
I gave as an input a csv file and using pandas we get a dictionary where the titles are the keys and the inputs are the values.
From that we get the below :
I have written the below endpoint to get all the islands that belog to the specific municipality :
Code:
@app.route("/municipality/<municipality>",methods=["GET"])
def get_island_municipality(municipality):
dict_to_send = {}
dict_to_send["data"] = get_islands_municipality(municipality)
dict_to_send["message"]=f'These are the islands that belong to {municipality}'
return jsonify(dict_to_send)
Code:
def get_islands_municipality(municipality):
islands = []
for i in range(len(dataframe["Municipality"])) :
islands_dict = {}
if dataframe["Municipality"][i] == municipality :
islands_dict["Island's Name"] = dataframe["Island's Name"][i]
islands_dict["Municipality"] = dataframe["Municipality"][i]
islands_dict["Amount of Hotels"] = dataframe["Amount of Hotels"][i]
islands_dict["Amount of Beaches"] = dataframe["Amount of Beaches"][i]
islands.append(islands_dict)
return islands
but I get an error, I suppose that the error relates to the type of my return. I return an array of dictionaries, right? Is that not allowed? The error that I get is "TypeError: Object of type int64 is not JSON serializable".
:unsure: