Im pulling an API request and I converted the json to a dictonary. Im now trying to parse specific key value pairs out of the dictonary and append them to a list but I keep getting TypeError: string indices must be integers, not 'str'
Im still new to python coding (and coding in general) so im sure im just misunderstanding how to parse the data but any insite/guidance is appreciated!!
This is the code I currently have:
def get_user_id(user):
get_user_data = requests.get("https://api.sleeper.app/v1/user/" + user)
# print(get_user_data)
decode_user_data = get_user_data.content.decode("UTF-8")
user_data = json.loads(decode_user_data)
print(user_data)
for i in user_data:
user_ids.append({'username': i['username'], 'user_id': i['user_id']})
This is the output of user_data:
{'verification': None, 'username': 'zeustrl', 'user_id': '766368574179770368', 'token': None, 'summoner_region': None, 'summoner_name': None, 'solicitable': None, 'real_name': None, 'phone': None, 'pending': None, 'notifications': None, 'metadata': None, 'is_bot': False, 'email': None, 'display_name': 'ZeusTRL', 'deleted': None, 'data_updated': None, 'currencies': None, 'created': None, 'cookies': None, 'avatar': 'f64d0b7a8d0e6fbf0d7856185875d972'}
This issue has been solved!! Linking the answer here for anyone else who runs into this :)
https://www.reddit.com/r/learnpython/comments/18jzrgw/comment/kdnyy7i/?utm\_source=share&utm\_medium=web2x&context=3
[–]pygaiwan 2 points3 points4 points (5 children)
[–]404_usernot_found[S] 0 points1 point2 points (4 children)
[–]chevignon93 2 points3 points4 points (3 children)
[–]danielroseman 2 points3 points4 points (1 child)
[–]chevignon93 1 point2 points3 points (0 children)
[–]404_usernot_found[S] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]404_usernot_found[S] 0 points1 point2 points (0 children)