#๐ Minecraft skin on Image not working
26 messages ยท Page 1 of 1 (latest)
@rich plank
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.
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
(incorrect ign, incorrect uuid, etc.)
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
alr so if i recode it into aiohttp it might work?
wait hollup what i gotta do to fix it?
and what is a match case
probably not, just saying that aiohttp is async, just like the rest of your code. currently you are using requests which will block the io stream and prevent anyone else from using commands until it finishes the request
oh thanks ill recode it to asiohttp then much better if multiple users can use it at once
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.
alright thanks
i tried out the same website that you used but i only get 200's
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.
and you seem to be calling the request twice..
oh what
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
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.