zeroone2numeral2 / sticker-thief

Telegram bot to build custom sticker packs
https://t.me/stickersthiefbot
MIT License
69 stars 42 forks source link

An error occurred while processing the message: cannot identify image file <tempfile.SpooledTemporaryFile object at 0x113846940> #17

Closed albertoxamin closed 3 years ago

albertoxamin commented 4 years ago

image

[2019-11-05 22:05:19,933][bot.sticker.stickers][stickers:__init__:40][DEBUG] >>> StickerFile object is a Sticker
[2019-11-05 22:05:19,934][bot.sticker.stickers][stickers:download:76][DEBUG] >>> downloading sticker
[2019-11-05 22:05:19,985][bot.sticker.stickers][stickers:download:79][DEBUG] >>> downloading to bytes object: self._tempfile_downloaded
[2019-11-05 22:05:20,025][bot.sticker.stickers][stickers:prepare_png:87][INFO] >>> preparing png
[2019-11-05 22:05:20,071][bot.utils.helpers.decorators][decorators:wrapped:35][ERROR] >>> error while running handler callback: cannot identify image file <tempfile.SpooledTemporaryFile object at 0x113846940>
Traceback (most recent call last):
  File "/Users/alberto/Downloads/sticker-thief-fad11ab8c575a60a0aa1b906dab4c7b20c0821ce/bot/utils/helpers/decorators.py", line 33, in wrapped
    return func(update, context, *args, **kwargs)
  File "/Users/alberto/Downloads/sticker-thief-fad11ab8c575a60a0aa1b906dab4c7b20c0821ce/bot/handlers/packs/create.py", line 143, in on_first_sticker_receive
    sticker.download(prepare_png=True)
  File "/Users/alberto/Downloads/sticker-thief-fad11ab8c575a60a0aa1b906dab4c7b20c0821ce/bot/sticker/stickers.py", line 84, in download
    return self.prepare_png()
  File "/Users/alberto/Downloads/sticker-thief-fad11ab8c575a60a0aa1b906dab4c7b20c0821ce/bot/sticker/stickers.py", line 89, in prepare_png
    im = Image.open(self._tempfile_downloaded)  # try to open bytes object
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PIL/Image.py", line 2330, in open
    % (filename if filename else fp))
OSError: cannot identify image file <tempfile.SpooledTemporaryFile object at 0x113846940>
zeroone2numeral2 commented 4 years ago

@albertoxamin sorry, for some reasons I haven't received any notification from GitHub about this issue.

I've just now updated the bot with a few bugfixes. Can you update your bot and try to create a pack now?

zeroone2numeral2 commented 4 years ago

Just checked the logs and apparently I get a similar error too:

[2019-11-20 22:30:21,424][bot.handlers.stickers.topng][topng:on_sticker_receive:19][INFO] >>> user sent a stciker to convert
[2019-11-20 22:30:21,425][bot.sticker.stickers][stickers:__init__:40][DEBUG] >>> StickerFile object is a Sticker
[2019-11-20 22:30:21,427][bot.sticker.stickers][stickers:download:82][DEBUG] >>> downloading sticker
[2019-11-20 22:30:21,446][bot.sticker.stickers][stickers:download:85][DEBUG] >>> downloading to bytes object: self._tempfile_downloaded
[2019-11-20 22:30:21,455][bot.sticker.stickers][stickers:prepare_png:93][INFO] >>> preparing png
[2019-11-20 22:30:21,457][bot.utils.helpers.decorators][decorators:wrapped:35][ERROR] >>> error while running handler callback: cannot identify image file <tempfile.SpooledTemporaryFile object at 0x7f1694089b38>
Traceback (most recent call last):
  File "/root/sticker-thief/bot/utils/helpers/decorators.py", line 33, in wrapped
    return func(update, context, *args, **kwargs)
  File "/root/sticker-thief/bot/handlers/stickers/topng.py", line 22, in on_sticker_receive
    sticker.download(prepare_png=True)
  File "/root/sticker-thief/bot/sticker/stickers.py", line 90, in download
    return self.prepare_png()
  File "/root/sticker-thief/bot/sticker/stickers.py", line 95, in prepare_png
    im = Image.open(self._tempfile_downloaded)  # try to open bytes object
  File "/root/sticker-thief/venv/lib/python3.5/site-packages/PIL/Image.py", line 2818, in open
    raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file <tempfile.SpooledTemporaryFile object at 0x7f1694089b38>

A good thing to do would be catching what stickers/pngs are causing this problem, because it only happens with some stickers.

This probably is an issue with what happens between downloading the webp from Telegram and converting it to png. PIL is likely receiving an already corrupted file

zeroone2numeral2 commented 3 years ago

Since 4cfd03a, the bot doesn't do the png conversion anymore. I've just checked the error logs from the past 6 months and there is no trace of that error. I will close the issue in the upcoming months if nobody reports such OSError again

albertoxamin commented 3 years ago

Sorry for the late response, I just checked and it is working now thanks!