'Python-3 Minecraft UUID to Username using the Requests library

I am wondering if it is possible to take a minecraft UUID and convert it into the users current username. I know how to get all of there previous usernames, but I dont know how to single out the newest one, I am able to do this with the mojang API.

import requests
data = requests.get("https://api.mojang.com/user/profiles/UUID/names")
print(data.content)


Solution 1:[1]

SOLUTION

I figured it out, I did the following.

data = requests.get("https://sessionserver.mojang.com/session/minecraft/profile/uuid").json()
print(data["name"])

NOTE: The UUID must be given with out dashes ("-")

Solution 2:[2]

this should work but it has no parseing

r = requests.get(f'https://api.mojang.com/users/profiles/minecraft/notchat=0').json()
uuid = r['id']
r2 = requests.get(f'https://api.mojang.com/user/profiles/{uuid}/names').json()
print(r2)

Solution 3:[3]

A few lines of code can do the trick.

import requests

uuid = ["enter UUID here"]
#uuid can be a list or a single string

for i in uuid:
    data = requests.get(f"https://sessionserver.mojang.com/session/minecraft/profile/{i}").json()
    print(data["name"])

Good for converting mass amounts of UUID's into IGNs without using namemc. Hope this helped.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 EchoTheAlpha
Solution 2 ryan
Solution 3 misplacements