Q: python: TypeError: list indices must be integers or slices, not str I was trying almost everything, and all the time I have the same problem :< 
from flask import Flask, request

app = Flask(__name__)

users =[]

@app.route("/user/<username>/set-password", methods=["POST"])
def set_password(username):
     data=request.get_json()
     new_password = data["password"]
     users[username] = new_password
     return "Set password of {} to '()' "\
         .format(username, new_password)

app.run(debug=True)


A: It looks like "users" is a list, and "username" is probably a string. You likely want "users" to be a dict:
users = {}

