I want to apply my skin from a png file with the mojang/minecraft java api
I’m trying to apply a skin with a file, and I did everything according to the mojang api docs (https://mojang-api-docs.gapple.pw/needs-auth/change-skin) but it keeps throwing a 500 Internal Server Error. Does anyone know why? It works when applying from a url but not from a file
import requests
import base64
file_path = 'F:\!! Chrome Downloads\'
skin_file = 'ec588a08f5eb3c6d.png'
full_path = file_path+skin_file
url = 'https://api.minecraftservices.com/minecraft/profile/skins'
auth_token = <authorization>
def png_file_to_binary_file(file):
with open(file, "rb") as f:
png_encoded = base64.b64encode(f.read())
encoded_b2 = "".join([format(n, '08b') for n in png_encoded])
return encoded_b2
binary_png = png_file_to_binary_file(full_path)
headers = {
'Authorization':auth_token,
}
payload = {
"variant": "slim",
"file": binary_png
}
req = requests.post(url=url,headers=headers,data=payload)
print(req.status_code)
print(req.reason)
print(req.text)
New contributor
nitbits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.