shayypy / guilded.py

Asynchronous Guilded API wrapper for Python
https://guildedpy.rtfd.io
Other
133 stars 25 forks source link

Sending file raises guilded.errors.BadRequest: 400 error #32

Closed kintama48 closed 2 years ago

kintama48 commented 2 years ago

When I try to send a .png file via Context.send(), it raises the following error. I have been trying to get it to work for quite a while but to no avail.

Here is the code:

# # Create a QrCode with that accessToken
        qrCodePath = f"QRCode_{ctx.author.name}_{str(uuid.uuid4())[0:8]}.png"
        generate_qr(accessToken, qrCodePath)

        # # Send the QrCode to the user

        await ctx.send(embed=guilded.Embed(title="Use the QR Code Above to Login",
                                           description="If the QR code doesn't work, please try these "
                                                       "steps: "
                                                       "\n\n**1.** Delete the old QR on your device, "
                                                       "and get a new one"
                                                       "\n**2.** If that doesn't work either then scan the "
                                                       "QR code with another device",
                                           colour=guilded.Colour.dark_purple(),
                                           timestamp=now,
                                           ),
                       file=guilded.File(fp=qrCodePath))

Here is the complete error log:

Ignoring exception in command qr:
Traceback (most recent call last):
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/ext/commands/core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "Cryptic-Scholars-QR-Code-Bot.py", line 74, in qr
    await ctx.send(embed=guilded.Embed(title="Use the QR Code Above to Login",
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/abc.py", line 254, in send
    data = await self._state.create_channel_message(
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/http.py", line 1614, in request
    return await perform()
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/http.py", line 1610, in perform
    raise exception(response, data)
guilded.errors.BadRequest: 400 (BadRequestError): Unsupported Content-Type header. Supported values: application/json

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

Traceback (most recent call last):
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/ext/commands/bot.py", line 421, in invoke
    await ctx.command.invoke(ctx)
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/ext/commands/core.py", line 619, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/kintama/Downloads/jerald/Cryptic-QR-Code-for-Guilded/venv/lib/python3.8/site-packages/guilded/ext/commands/core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
guilded.ext.commands.errors.CommandInvokeError: Command raised an exception: BadRequest: 400 (BadRequestError): Unsupported Content-Type header. Supported values: application/json
shayypy commented 2 years ago

Looks like you're using the bot API, in which case files should be ignored since they are not supported by the API.