"image file is truncated" error

I noticed that whenever I tried to open the folder for Doctor Who in the "All Shows" section, I would get a "Trailers is unavailable" error.  So I peered into the log file and found this:

 

16:50:35 XMLConverter: Background (Source): http://[...]/library/metadata/3117/art/1419654786
16:50:35 XMLConverter: XML_ExpandLine - Error in {{BACKGROUNDURL(art:)}}
Traceback (most recent call last):
  File "[..]/PlexConnect/XMLConverter.py", line 495, in XML_ExpandLine
    res = getattr(CommandCollection, 'ATTRIB_'+cmd)(src, srcXML, param)
  File "[..]/PlexConnect/XMLConverter.py", line 1227, in ATTRIB_BACKGROUNDURL
    res = res + PILBackgrounds.generate(self.PMS_uuid, key, auth_token, self.options['aTVScreenResolution'], g_ATVSettings.getSetting(self.ATV_udid, 'fanart_blur'))
  File "[..]/PlexConnect/PILBackgrounds.py", line 84, in generate
    background = background.resize((width, height), Image.ANTIALIAS)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 1531, in resize
    self.load()
  File "/Library/Python/2.7/site-packages/PIL/ImageFile.py", line 229, in load
    "(%d bytes not processed)" % len( B))

 

IOError: image file is truncated (3 bytes not processed)
 
 
If I open the art URL directly in the browser, the file does, in fact, appear truncated.  I have attached the jpeg generated by that URL to this post.
 
Please let me know what other information I can provide.  I updated my PlexConnect client from github right before posting this message.

Apparently my attachment failed...  Here is the image in question.

FWIW I 'fixed' this by changing the background art for the show...  

Someone marked this problem as 'solved', and while I found a workaround, i don't exactly think it is solved.  

It seems like this exception should be handled so that others can avoid this fate in the future.  I may take a wack at fixing this myself, but I haven't ever actually looked at the PC source, so it might be awhile.. :)

In the meantime, here is all of the relevant detail as per the Issue reporting guidelines:

ATV model: 2 

firmware version: 6.2.1 (6698.99.50.41)
 
The DNS server set on the ATV: 192.168.0.242
The local IP address of the device that PlexConnect is installed on: 192.168.0.242
 
The device and operating system (including version number) that PlexConnect is installed on:
Mac Mini Server running OS X 10.10.1
 
The device and operating system (including version number) that the Plex media server (PMS) is installed on:
Mac Mini Server running OS X 10.10.1
 
The Plex media server (PMS) version number you are running (do not put 'latest'):
Version 0.9.11.7
 
The local IP address of the device that the Plex media server (PMS) is installed on:
192.168.0.242
 
The PlexConnect version number. If using Github source then a time and date of download (look at the creation date of the folder) and if you are using any non-standard setup e.g. Plexify or a fork.
 
host:[~/src/PlexConnect]$ git pull
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 16 (delta 3), reused 6 (delta 0)
Unpacking objects: 100% (16/16), done.
   5b421ce..c943e31  master     -> origin/master
 * [new branch]      Gzip_Benchmark -> origin/Gzip_Benchmark
(using stock code)
 
The contents of your 'Settings.cfg' file (this is created at first clean shutdown of PlexConnect, using CTR+c)
 
[PlexConnect]
enable_plexgdm = True
ip_pms = 192.168.0.242
port_pms = 32400
enable_dnsserver = False
port_dnsserver = 53
ip_dnsmaster = 192.168.0.242
prevent_atv_update = True
enable_plexconnect_autodetect = False
ip_plexconnect = 192.168.0.243
hosttointercept = trailers.apple.com
port_webserver = 80
enable_webserver_ssl = True
port_ssl = 443
certfile = ./assets/certificates/trailers.pem
loglevel = Normal
logpath = .
 
 
A detailed description of the issue (the clearer you can make this the better):
Somehow my PMS grabbed an invalid JPEG as one of the backgrounds.  You can
get this file here:
 
If this is configured as the background for the show (Doctor Who (2005) and
in PlexConnect open:
Trailers -> Library -> TV Shows -> All Shows -> Doctor Who (2005)
 
I get a "Trailers is unavailable.  Try again later." error message.  IIRC,
this also happens if I try to open an episode from the On Deck circle, but I
did not capture that for the logs.  
 
If I change the background for the show everything goes back to working
hunky-dory.  While this is an adequate workaround for me, it seems that this
exception could be caught and handled a bit more gracefully.
 
Here is the relevant log snippet (with a link to the full logs below)
[..]
19:36:26 XMLConverter: XML_ExpandLine - Error in {{BACKGROUNDURL(art:)}}
Traceback (most recent call last):
  File "/Users/grahams/src/PlexConnect/XMLConverter.py", line 496, in XML_ExpandLine
    res = getattr(CommandCollection, 'ATTRIB_'+cmd)(src, srcXML, param)
  File "/Users/grahams/src/PlexConnect/XMLConverter.py", line 1229, in ATTRIB_BACKGROUNDURL
    res = res + PILBackgrounds.generate(self.PMS_uuid, key, auth_token, self.options['aTVScreenResolution'], g_ATVSettings.getSetting(self.ATV_udid, 'fanart_blur'))
  File "/Users/grahams/src/PlexConnect/PILBackgrounds.py", line 84, in generate
    background = background.resize((width, height), Image.ANTIALIAS)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 1531, in resize
    self.load()
  File "/Library/Python/2.7/site-packages/PIL/ImageFile.py", line 229, in load
    "(%d bytes not processed)" % len( B))
IOError: image file is truncated (3 bytes not processed)
 
Full log file available at: 
(line ~29603)

Extra error checking has now been added :slight_smile:

I pulled the latest source and this fixed the issue, thanks!