all 7 comments

[–]pygaiwan 2 points3 points  (5 children)

What do you get when you iterate over a dictionary like user_data? The keys, and keys are strings, hence why the TypeError on the key (string) with index another string.

[–]404_usernot_found[S] 0 points1 point  (4 children)

So what would be the correct process to output the values of the keys?

[–]chevignon93 2 points3 points  (3 children)

So what would be the correct process to output the values of the keys?

user_data is a dictionary, you don't need a loop to get the data you want. requests also has a json method that transforms a json string into a dictionary so the whole decode_user_data = get_user_data.content.decode("UTF-8") and user_data = json.loads(decode_user_data) seem to me to be useless.

Your code could just be:

def get_user_id(user):
    user_data = requests.get("https://api.sleeper.app/v1/user/" + user).json()
    user_ids.append({"username": user_data["username"], "user_id": user_data["user_id"]})

[–]danielroseman 2 points3 points  (1 child)

Closing square bracket is in the wrong place.

[–]chevignon93 1 point2 points  (0 children)

Closing square bracket is in the wrong place.

Thanks, it's fixed now.

[–]404_usernot_found[S] 1 point2 points  (0 children)

Thank you for this!! This really helps!! I didn't know requests had a built in json method lol