#๐Ÿ”’ Minecraft skin on Image not working

26 messages ยท Page 1 of 1 (latest)

rich plank
#

so i am trying to make a stats image for my discord bot but i want to put the user's skin on the image but its not working
this is the status error i get: "Failed to fetch skin image. Status code: 400"

this is my code: https://paste.nextcord.dev/?id=1712945256387683

modern bearBOT
#

@rich plank

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rich plank
#

this is my image atm:

#

this is how i want the skin to be:

gleaming tapir
#

code 400 usually means that the request you sent in was unrecognized (probably some incorrect info in the request)

#

and just a recommendation, but instead of a long if elif statement, use a match case

gleaming tapir
#

also you are using async functions but also using requests... requests is a blocking library (isnt async) and it could cause problems down the road. try out aiohttp instead @rich plank

rich plank
#

alr so if i recode it into aiohttp it might work?

rich plank
#

and what is a match case

gleaming tapir
rich plank
half cobalt
#

an alternative would be to run the request in a thread via asyncio.to_thread, but sure, using an async requests library would be nicer.

rich plank
#

alright thanks

gleaming tapir
#

i tried out the same website that you used but i only get 200's

half cobalt
#

quite possibly the server actually tells you what the problem is in the response body, OP. by only reading the status code you can miss out on information.

gleaming tapir
#

and you seem to be calling the request twice..

rich plank
#

oh what

rich plank
# gleaming tapir and you seem to be calling the request twice..

this is the api i made for the basic info:

    async def get_basic_info(self, uuid):
        url = f"{API_BASE_URL}/player/info/{uuid}?api={API_KEY}"
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                if response.status == 200:
                    return await response.json()
                else:
                    raise Exception("Failed to fetch player basic info")```
#

and this is the error i get

#
Traceback (most recent call last):
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 131, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 1009, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "c:\dev\cogs\profile.py", line 67, in profile
    basic_info = await self.get_basic_info(uuid)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\dev\cogs\profile.py", line 30, in get_basic_info
    return await response.json()
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiohttp\client_reqrep.py", line 1166, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://api.voxyl.net/player/info/bf05da0290e64bf38472e0b3d45297eb?api=nsmwAbiswnhpRsPiuRMVeZ0eukoudRvC')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\bot.py", line 1130, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 376, in invoke
    await injected(ctx)
  File "C:\Users\janne\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 139, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/plain', url=URL('https://api.voxyl.net/player/info/bf05da0290e64bf38472e0b3d45297eb?api=nsmwAbiswnhpRsPiuRMVeZ0eukoudRvC')```
#

well i fixed this

#

just the skin image now and i switched to aiohttp

modern bearBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.