I made a little script to get the UUID's of people who joined my minecraft server, then run them through the PlayerDB API through a post request to: https://playerdb.co/api/player/minecraft/* where the * is a player UUID, however it returns random 404 errors.
Error runs on the player_name_history line and highlights KeyError at 'player':
def getPlayerData(UUID_list):baseurl = "https://playerdb.co/api/player/minecraft/"player_names=[]icon_list = []for UUID in UUID_list:response = requests.post(baseurl+UUID)print("url posted:",baseurl+UUID)print(response.status_code)responseObject = response.json()with open('responseObject.json','w') as f:json.dump(responseObject, f)player_name_history = responseObject['data']['player']['meta']['name_history']for x in player_name_history:player_name = x['name'] #iterates through all names, last name will not be overrwrittenplayer_names.append(player_name)icon_link = responseObject['data']['player']['avatar']icon_list.append(icon_link)return player_names, icon_listfor x in player_name_history:player_name = x['name'] #iterates through all names, last name will not be overrwrittenplayer_names.append(player_name)icon_link = responseObject['data']['player']['avatar']icon_list.append(icon_link)return player_names, icon_list
You can pass my UUID into the function as a list to test:
['bf22088f-3d5b-45ef-b7dd-8d5bd3cdc310']
Example of it working:
url posted: https://playerdb.co/api/player/minecraft/bf22088f-3d5b-45ef-b7dd-8d5bd3cdc310
200
(['zonkedzolt'], ['https://crafthead.net/avatar/bf22088f-3d5b-45ef-b7dd-8d5bd3cdc310'])
Example of it not working:
url posted: https://playerdb.co/api/player/minecraft/bf22088f-3d5b-45ef-b7dd-8d5bd3cdc310
404
Traceback (most recent call last):File "g:\*\getPlayerData.py", line 74, in <module>print(getPlayerData(UUID_list))File "g:\*\getPlayerData.py", line 58, in getPlayerDataplayer_name_history = responseObject['data']['player']['meta']['name_history']
KeyError: 'player'
json Dump: {"message": "", "code": "api.404", "data": {}, "success": false, "error": false}
The reason why i suspect it might be my code is because when i get the error, if i ctrl+left click the link on the "url posted:" line it brings up the correct result.