Waifu-pics / waifu-api

https://waifu.pics Image sharing platform and API for anime images, entirely user curated (joke gone too far)
https://waifu.pics
ISC License
434 stars 35 forks source link

api doesn't working for discord.py #35

Closed doumeem closed 3 years ago

doumeem commented 3 years ago

hi i'm getting this error when i print the response as json

error in waifu
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped       
    ret = await coro(*args, **kwargs)
  File "d:\Projects\Coding Projects\Python\DiscordBOT\config\commands\fun.py", line 17, in wafiu
    r = await respone.json()
  File "C:\Program Files\Python39\lib\site-packages\aiohttp\client_reqrep.py", line 1097, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.waifu.pics/sfw/waifu')

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

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke        
    await ctx.command.invoke(ctx)
  File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke       
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped       
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.waifu.pics/sfw/waifu')

when i print the response as txt/text, it's say that

<p>Your client does not have permission to get URL <code>/sfw/waifu</code> from this server.  <ins>That’s all we know.</ins>
doumeem commented 3 years ago

i forgot to post the code

    # Waifu
    @commands.command(name="waifu", aliases=["wf"], help="Will send a waifu image")
    async def wafiu(self, ctx):
        async with aiohttp.ClientSession() as session:
            async with session.get("https://api.waifu.pics/sfw/waifu") as response:
                r = await responsse.txt()
                print(r)
JSH32 commented 3 years ago

This is an unrelated issue to the API. Have just verified api is working properly. This is an issue with your code or discord.py