LowellObservatory / NightShift

Collection of sub-modules used in the NightWatch (and other Night*) project
Mozilla Public License 2.0
1 stars 1 forks source link

Unhandled PIL exception #19

Closed astrobokonon closed 3 years ago

astrobokonon commented 3 years ago

Another odd one

2021-03-25 11:46:52,748 INFO     Retrieving camera image: UpperGate
2021-03-25 11:46:52,748 INFO     Attempting to write image to ./outputs/images/dct//gate.jpg
2021-03-25 11:46:53,319 INFO     Good grab!
2021-03-25 11:46:53,448 ERROR    Traceback (most recent call last):
2021-03-25 11:46:53,448 ERROR      File "looper_webcams.py", line 64, in <module>
2021-03-25 11:46:53,448 ERROR    main()
2021-03-25 11:46:53,448 ERROR      File "looper_webcams.py", line 56, in main
2021-03-25 11:46:53,448 ERROR    cams.grabSet(oncams, failimg=None, archive=True, makeMini=True)
2021-03-25 11:46:53,448 ERROR      File "/home/lig/Codes/NightShift/nightshift/webcam/grab_cams.py", line 63, in grabSet
2021-03-25 11:46:53,448 ERROR    images.resizeImage(outfile, thumbfile, thumbSize)
2021-03-25 11:46:53,448 ERROR      File "/home/lig/Codes/NightShift/nightshift/common/images.py", line 28, in resizeImage
2021-03-25 11:46:53,449 ERROR    oimg = Image.open(infile)
2021-03-25 11:46:53,449 ERROR      File "/opt/conda/lib/python3.7/site-packages/PIL/Image.py", line 2896, in open
2021-03-25 11:46:53,451 ERROR    "cannot identify image file %r" % (filename if filename else fp)
2021-03-25 11:46:53,451 ERROR    PIL
2021-03-25 11:46:53,451 ERROR    .
2021-03-25 11:46:53,451 ERROR    UnidentifiedImageError
2021-03-25 11:46:53,451 ERROR    :
2021-03-25 11:46:53,451 ERROR    cannot identify image file './outputs/images/dct//gate.jpg'

This is related to the thumbnail creation, but at a glance I can't say why. Maybe the path got screwed up? But it says the grab was good.

astrobokonon commented 3 years ago

Normally I'd call this a network quirk, but everything was/is local so that's definitely not the case here.

astrobokonon commented 3 years ago

Curiously in the archive, the file (what should have probably been 20210325_114653.jpg) does not exist

20210325_114544.jpg                                25-Mar-2021 11:45                2356
20210325_114806.jpg                                25-Mar-2021 11:48                2341

Seems like I need to add some debug output to the archiving step, which is fine because I still needed to enable the archive culling so it's good to get both in there.

astrobokonon commented 3 years ago

The error implies that the image didn't actually write to disk properly, but "Good grab!" was in a with block so I don't really understand how that could be the case. It could be that the image was malformed even though it was all received, so it wasn't actually a valid image file?

Found an old PIL github issue and it seems like it got raised on a file of 0 bytes, so that must be it - I actually failed to get a valid image, even though the request didn't error out. I'll try to fix it at that level and be loud about it to trigger the error image.

astrobokonon commented 3 years ago

Got archive culling in as of 26d451704f88247cffb70bc2e627e64205c3b5d7 so I think I'm done here.