fabianonline / OctoPrint-Telegram

Plugin for octoprint to send status messages and receive commands via Telegram messenger.
311 stars 114 forks source link

IMAGE_PROCESS_FAILED for snapshots from ustreamer #380

Open IATkachenko opened 2 years ago

IATkachenko commented 2 years ago

Hello.

I'm using ustreamer as interface to USB web camera. Plugin log for /status command is

2021-10-12 12:09:23,921 - octoprint.plugins.telegram - DEBUG - start _send_msg
2021-10-12 12:09:23,923 - octoprint.plugins.telegram - DEBUG - PreImgMethod None
2021-10-12 12:09:23,928 - octoprint.plugins.telegram - DEBUG - log instead log sending message 
2021-10-12 12:09:23,929 - octoprint.plugins.telegram - DEBUG - data so far: {'disable_web_page_preview': True, 'chat_id': '264540708', 'disable_notification': False}
2021-10-12 12:09:23,934 - octoprint.plugins.telegram - DEBUG - Snapshot URL: http://<valid snapshot url>:8080/snapshot
2021-10-12 12:09:23,949 - octoprint.plugins.telegram - DEBUG - Image transformations [H:False, V:False, R:False]
2021-10-12 12:09:23,952 - octoprint.plugins.telegram - DEBUG - message so far: Printing at Z=20.4.
Bed 50.71/50.0, Extruder 205.0/205.0.
11:11:20, 25% done, 11:11:49 remaining.
Completed time 11:11:12.
2021-10-12 12:09:23,952 - octoprint.plugins.telegram - DEBUG - Sending with image.. 264540708
2021-10-12 12:09:24,658 - octoprint.plugins.telegram - DEBUG - Sending finished. 400
2021-10-12 12:09:24,661 - octoprint.plugins.telegram - DEBUG - PostImgMethod None

and no status reported.

If I print r.text

r = requests.post(
                        bot_url + "/sendPhoto",
                        files=files,
                        data=data
                    )
print(r.status_code)
print(r.text)

I have got

400
{"ok":false,"error_code":400,"description":"Bad Request: IMAGE_PROCESS_FAILED"}

After turning on "Flip webcam horizontally" in OctoPrint settings all works fine.

Ustreamer is producing valid JPEG:

# curl http://<valid snapshot url>:8080/snapshot >/tmp/img.jpg
# file /tmp/img.jpg 
/tmp/img.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 96x96, segment length 16

It's look like something goes wrong in take_image function.

Following code

image_data = requests.get(snapshot_url, timeout=10).content
image = Image.open(bytes_reader_class(image_data))
output = bytes_reader_class()
image.save(output, format="JPEG")
image_data = output.getvalue()
output.close()

also produce valid image for Telegram.

Have no idea what is going wrong with original image_data. Please let me know if you need additional tests.

giloser commented 2 years ago

Hi,

I have take a look at your analyse and to the function , I will test a change and if everything seems to work fine for me, I'll give you a link for a test version.

giloser commented 2 years ago

Hi,

could you try this version? https://github.com/giloser/OctoPrint-Telegram/archive/refs/heads/master.zip

thanks

IATkachenko commented 2 years ago

@giloser, thank you. I'll test it in few days.

IATkachenko commented 2 years ago

@giloser, hello.

could you try this version? https://github.com/giloser/OctoPrint-Telegram/archive/refs/heads/master.zip

This version works well, thank you.

ps. I have tested just changes in take_image.