Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error sending PNG to "create_custom_emoji" #9584

Closed
3 tasks done
michaelstephens opened this issue Sep 28, 2023 · 3 comments
Closed
3 tasks done

Error sending PNG to "create_custom_emoji" #9584

michaelstephens opened this issue Sep 28, 2023 · 3 comments
Labels
invalid This is not right.

Comments

@michaelstephens
Copy link

michaelstephens commented Sep 28, 2023

Summary

Not recognizing PNG in create_custom_emoji

Reproduction Steps

Upload a local png file to a guild using:

guild.create_custom_emoji()

Minimal Reproducible Code

with open("icons/emoji/reply-continue.png", "rb") as emoji_file:
    print(emoji_file.read())
    emoji = await guild.create_custom_emoji(name="reply-continue", image=emoji_file.read())

Expected Results

PNG file correctly uploads and creates a custom emoji

Actual Results

Traceback (most recent call last):
  File "/home/USR/repos/eww-bot/src/helpers.py", line 252, in emoji_list
    emoji = await guild.create_custom_emoji(name="reply-continue", image=emoji_file.read())
  File "/home/USR/.local/lib/python3.10/site-packages/discord/guild.py", line 3302, in create_custom_emoji
    img = utils._bytes_to_base64_data(image)
  File "/home/USR/.local/lib/python3.10/site-packages/discord/utils.py", line 627, in _bytes_to_base64_data
    mime = _get_mime_type_for_image(data)
  File "/home/USR/.local/lib/python3.10/site-packages/discord/utils.py", line 622, in _get_mime_type_for_image
    raise ValueError('Unsupported image type given')
ValueError: Unsupported image type given

Intents

intents.members = True

System Information

- Python v3.10.12-final
- discord.py v2.3.2-final
- aiohttp v3.8.5
- system info: Linux 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

the _get_mime_type_for_image method checks for data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'), but my pngs start with b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR

here is the image info:
reply-continue

b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00`\x00\x00\x00`\x08\x06\x00\x00\x00\xe2\x98w8\x00\x00\x00 cHRM\x00\x00z&\x00\x00\x80\x8
4\x00\x00\xfa\x00\x00\x00\x80\xe8\x00\x00u0\x00\x00\xea`\x00\x00:\x98\x00\x00\x17p\x9c\xbaQ<\x00\x00\x00\x06bKGD\x00\xff\x00\xff\x00\xf
f\xa0\xbd\xa7\x93\x00\x00\t\x02IDATx\xda\xed\x9d]LT\xcb\x1d\xc0\xff\xff\x99s\\\xd6\x05\x84\xbb \xa2\xab\xcbGYXH\x1a\xc5\xca\x95"\xa2\x0
fU\x12\x13\xd2\x07H#\xb9Q\xa2\xb1\xa6\xe6\xde\x07c\x13\xdb>4\xed[cl\x9a\xf4\xc1\x18M\xca\x954F\xdb\x94\xf8T\x93\x92x\r\x84\xa5\xd1XA>\x
82D\xa4\x14\x04\xb1^aY\xbe\xf6pf\xfe}`\x97\xac.\x1f\xde\x82;\xe8\x9e_rBr\xf6\xec\x9c\x99\xf9\xcd\xfcg\xce9\xb3\x07\x845r\xfe\xfc\xf9e?#
"HJJ\x82[\xb7n\xa1a\x18p\xe2\xc4\t\x92R\x02\xe7\x1c\x00\x00\x84\x10p\xf3\xe6\xcd\x15\xd3\x1f\x18\x18Xk\x1674\xecC%\x8c\x88\xd0\xd1\xd1\
x81\xc1`\x10=\x1e\x0ffeeaKK\x0b\xb6\xb6\xb6"\xc0\x82\x1c\xc6>\xd8\xe9?\x1a\xb4\x0f\x99xrr2\x18\x86\xb1\xd5\xeb\xf5~\x9f\x886\x8d\x8d\x8
d\xfd+;;{\xf4\xc9\x93\'XTTD\xaa\x0b\xbf\x11\xf8 \x02\xee\xdf\xbf\x8fN\xa73\xb5\xb4\xb4\xf4LVV\xd6/9\xe7\xc9\x00\x00\x1e\x8f\xc7\x8f\x88
\xd7[[[\xff\xc09\x7fIDq/a\xddc\xc0\xe3\xc7\x8f1--\xcd^\\\\|*77\xf7\x17\xa6i&\x07\x83A\n\x06\x83\x04\x00[8\xe7_\xd6\xd4\xd4\\@DhiiA\xd5\
x15\xa0\x9au\x17PPP\x80\x83\x83\x83;=\x1e\xcfq\xc30\x92\x00\x00C\xe7a\x00\x80\x86a\xd8t]?300\xb0\xd3\xef\xf7\xc3\xf8\xf8\xf8\xa2\x04)\x
a5\xea\xfa\x889\xeb.\xc0n\xb7\xcb\x8b\x17/\xee\x12B\xe4\x13QT\xfa\x8c1\xd04-\xd1\xe9t\xee\xcb\xc8\xc8@\xa7\xd3\t\x00\x0b\x83vxv\x14O\xa
c\xbb\x00D\x84\x99\x99\x19;\x00hK\xb5\xe8\xd0>\x04\x00[FF\x06$&&\x02"\x82\x10\x02\xe2qHX\xf3 \x9c\x97\x97\x17\xb5\xcf4M\x00\x80%\xa7\x9
9\x91\xfb\x88\x08\x10\x11\x92\x93\x93U\xd7\x832\xac\x89\xb8b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K
\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xe6\x83\xae\x8ax_L\xd3\x04D\x8c\xcb\x072V\x0fP\x8c%@1\x96\x00\xc5(\x11\
xc0\x18\x8bZ\x05\x11\x8f\xf1\x1f@\x91\x00"\x02"\x02!\x04 \xe2[\xfb\xe3\x8d\x98\x0b\x08/AAD\x9ba\x18`\x18\x86\xea:PJ\xcc\x05\x10Q8\xf4$\
xbf|\xf9\x12fff\x00`ALdo\x88\x17\x94\\\x07\x84\x16am\x0b/\xce-//_\xf6\xd8\xae\xae.EU\x13\x1bT\x8c\x01(\x84@\xb7\xdb\x9d\xcb9\xd7\xc2!(\
x1e[?\x80"\x01RJ\xda\xbcy\xb3\xdbn\xb7\xa7WWW/\xfe`#\x1c\x86"\xb7O\x1dU\xd7\x01R\xd3\xb44\x00\xc8\t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5\xb5\xf57\x9a\
xa6\xb5\xec\xde\xbd;\xd8\xd4\xd4Duuu\x14\x96\x86\x88PYY\xb9\x98&c\xec;KZ\xab\xd4\x95^\xaf \xa5\x84\x91\x91\x91\x15\xbf\xbf\xe6w\x03\x1c
;vl\xa9\x13\xe7k\x9aV\x13J?*n\xbcG(\t\x1f\xe0\xca\xca\xca:PVV\xb6\xc5\xe7\xf3=KOO\x9flll\xc4\xe9\xe9i\x96\x9d\x9dM\x91\xe3\x82\xca\xf0\
xb4\xdc\xeds\xc6\x18LNN\xae\xf8]%\x02\xde\xb7\\\xa1\xbf)\x88X\x92\x93\x93\xf3\xb9\xae\xeb\xf0\xf4\xe9\xd3~\xbf\xdf\x1f\x9c\x98\x98@!\x0
4\xb7\xd9l\xa0\xeb\xfabE\xc4\x9a\x95z\x90\x94\x12\x02\x81\xc0{\x15\xf2\xff\xe6\xca\x95+Q\xfbL\xd3\xac\xb2\xd9l\x7f\x01\x80MK\x9c\x83\x1
0\x11\x85\x10O\x18c\xbb\x00`K\xe41\xefv\xe9P\x88"\x00\x00\xce9 \xe2\x7f\xa4\x94_\xfb|\xbe\xfbmmm\xff\x06\x80W.\x97k\xae\xb8\xb8\x18\xc6
\xc6\xc6\xbesy\xd6\x1a\x82\xde\x95ND\x90\x9c\x9c\x0c\x87\x0f\x1f\xa6\x93\'ORMM\xcd\x8a\'P!@&$$\xe0\xd0\xd0\xd0\xb9@ \x90\xe5\xf5z\x7f6;
;\x9b\xb8P\xd7\xab\xce\t(\xb4\xa6H"\xe2\xb7\x88\xd8#\xa5\xec\xe8\xeb\xeb{\xd6\xdb\xdb;*\x84\x18C\xc4i\x000!$M\x05\x88H\x88\x18\xf0\xf9|
C\xfb\xf6\xed\x83m\xdb\xb6\xd1r\xcf<\x94=\x94w\xb9\\\x81\xae\xae\xae\xcb\xcf\x9f?7\xddn\xf7\xafL\xd3$X\xbdA\xa0i\x9a\xc0\x18c\x88\x98\x
8e\x88\xe5R\xca\x83\xf9\xf9\xf9\xb3\x85\x85\x85\xd3\x000\x05\x00\xf3\x00\xa0\xfa\xc5C$\x84\x08\xe6\xe5\xe5\xfd\xbd\xa7\xa7\xe7\xba\xae\
xebC\xa6i\xca\xa5z[\xcc\x05\x84\xe6\xfc\xd0\xde\xdeN\xc3\xc3\xc3\xe3o\xde\xbc\xf9\xb5\x10b4;;\xfb\xe7R\xca\x1dD\xa4\xc1*"\xa4\x94\x18\x
9a\xf1pD\x04\xd347\x9b\xa6\x99\x00\x00\xce\xf0ib]\xae\x88\xbc\x01\x00\x00\xe7\x1c\xbd^\xefn\xaf\xd7\xfb\xa3\xdb\xb7o\x9f\x99\x9e\x9e\xe
e*((\x90\x00o\xf7\x02%\xeb\x82\x00\x16b;c\x8c233\xf1\xc1\x83\x07\x7f\xea\xec\xec<\xa7i\xda7\xe1\xc3`\x99\x10\x12\xfa\xde[\xe9\xe1B\xff\
xe6RJ\x0e\x0b\x03?S\xb5\x85!"\x94R\x12\x11\xfd\xa0\xba\xba\xfa\xb4\xdf\xef\'\xbf\xdf\x1f\xfd\x02\xabX\x0b\x08\xb7\x10"\x02\xbb\xdd\x0e\
xdd\xdd\xdd2\x10\x08\xcc\r\x0f\x0f\xff\xe3\xd2\xa5K?\x05\x80k\xba\xaeO!"\xca\x05V]!\x11)u#AD\x18\xca\xd7\xb1\x8a\x8a\n\xde\xdc\xdcL\x8c
1\xe0\x9c/n\x1b"\xc7999d\xb3\xd9\xc4\xd9\xb3g\x87\x1a\x1a\x1a\xbe\xec\xe8\xe88:77\xf7W\xbb\xdd\xfe-\xe7\\P\x08\x88\xe8\x15\x1f\xc9\xb2\
x15\x94R\xa2\x942\x951\xb6\xa9\xaa\xaa*\xaaW+\x17\x10Y\x89\x0f\x1f>\x94\xb9\xb9\xb9b~~\xfe\x9f\xf7\xee\xdd;\xd3\xdc\xdc|\x9es\xfe7\xce\
xf9\xab\xf0\x8aj\x08\x85\'""!\x84\xea\xec\xaf\x06q\xce\t\x00\xfa\xfb\xfb\xf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 \x02z\xe7\xafR\xea\xeb
\xeb\xdf\xeb8\xe5]5\xde\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,
\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x0
4(\xc6\x12\xa0\x18K\x80b,\x01\x8a\xb1\x04(\xc6\x12\xa0\x98\xff\x01\x13\x14\xc72\xae*5z\x00\x00\x00%tEXtdate:create\x002023-09-28T18:47:
28+00:00\xa8KJ\x1d\x00\x00\x00%tEXtdate:modify\x002023-09-28T18:47:28+00:00\xd9\x16\xf2\xa1\x00\x00\x00(tEXtdate:timestamp\x002023-09-28T18:47:43+00:00Jk\x8e\x03\x00\x00\x00\x00IEND\xaeB`\x82'
@michaelstephens michaelstephens added the unconfirmed bug A bug report that needs triaging label Sep 28, 2023
@fretgfr
Copy link
Contributor

fretgfr commented Sep 28, 2023

Your file is being read and then read again. The second time read is called there is not data to read.

If you want to print it first, read the contents into a separate variable and reuse it in both functions.

@Rapptz Rapptz added invalid This is not right. and removed unconfirmed bug A bug report that needs triaging labels Sep 28, 2023
@Rapptz Rapptz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@michaelstephens
Copy link
Author

Ha! Yeah you are right, removing the print does it. I'm still getting a:

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: String value did not match validation regex.

but that is probably on my end, thank you and apologies python newbie here

@itswilliboy
Copy link
Contributor

Yeah, you cannot have hyphens in emoji names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not right.
Projects
None yet
Development

No branches or pull requests

4 participants