# Dealing with image redirects?

**URL:** <https://forums.plex.tv/t/dealing-with-image-redirects/46160>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [November 5, 2013, 6:19am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160 "2013-11-05T06:19:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 5, 2013, 6:19am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/1 "2013-11-05T06:19:58Z")

</div>

Hey guys, working on another plugin. &nbsp;Having some dramas with my image urls returning 302 redirects when trying to use them as thumbs for TV Show Objects. &nbsp;If I open the url in a browser tab, I get the image fine. &nbsp;However, when using the same url as a thumb, its reverting to my fallback image. &nbsp;Any idea why? &nbsp;I have used the same code for a different site recently with no dramas. Could this be some kind of hotlink protection? &nbsp;Thanks in advance.

&nbsp;

&nbsp;

Example URL:

```
http://aniverse.tv/wp-content/uploads/2013/08/Asu-No-Yoichi.png
```

Relevant Code:

```
@route("/video/aniverse/showcategory")	
def ShowCategory(title, category):

```
oc = ObjectContainer(title1 = title)
page_data = HTML.ElementFromURL(BASE_URL + str(category))
count = 0

for each in page_data.xpath("//div[@id='anime']/a"):

	show_url = each.xpath("./@href")[0]
	show_title = each.xpath("./div[@class='tooltip']/span[@class='tip']/h1/text()")[0]
	show_thumb = each.xpath("./div[@class='tooltip']/img/@src")[0]
	show_summary = each.xpath("./div[@class='tooltip']/span[@class='tip']/p[1]/text()")[0].strip()
	show_genres = each.xpath("./div[@class='tooltip']/span[@class='tip']/h2/text()")[0].split(", ")
	
	oc.add(TVShowObject(
		key = Callback(PageEpisodes, show_title = show_title, show_url = show_url),
		rating_key = show_title,
		title = show_title,
		thumb = Resource.ContentsOfURLWithFallback(url = show_thumb, fallback='icon-cover.png'),
		summary = show_summary,
		genres = show_genres
		)
	)
	
	count = count + 1
	if count == 30:
		break
		
return oc

```
```

Relevant Plugin Log:

```
2013-11-05 15:50:17,559 (-4f877490) : DEBUG (runtime:717) - Handling request GET /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FArea-no-Kishi.png
2013-11-05 15:50:17,561 (-4f877490) : DEBUG (runtime:814) - Found route matching /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback
2013-11-05 15:50:17,562 (-4f877490) : DEBUG (networking:233) - Fetching HTTP headers for 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:18,357 (-4f877490) : DEBUG (networking:172) - Requesting 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:24,156 (-4f877490) : ERROR (networking:219) - Error opening URL 'http://aniverse.tv/wp-content/uploads/2013/08/Area-no-Kishi.png'
2013-11-05 15:50:24,158 (-4f877490) : DEBUG (runtime:914) - Response: [302] Redirect, 0 bytes
2013-11-05 15:50:24,161 (-4f877490) : DEBUG (runtime:717) - Handling request GET /:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
2013-11-05 15:50:24,163 (-4f877490) : DEBUG (runtime:814) - Found route matching /:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png
2013-11-05 15:50:24,166 (-4f877490) : DEBUG (runtime:914) - Response: [200] DataObject, 65338 bytes
```

Relevant PMS Log:

```
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Request: HEAD /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53764] (9 live)
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - * height => 720
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - * width => 720
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - * fallback => icon-cover.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - * urls => http%3A//aniverse.tv/wp-content/uploads/2013/08/Asu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - Plug-in com.plexapp.plugins.aniverse has been used 220 times.
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - [com.plexapp.plugins.aniverse] Sending command over HTTP (GET): /:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:16 [0xa3fffb70] DEBUG - HTTP requesting to: http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - [com.plexapp.plugins.aniverse] HTTP reply status 302, with 0 bytes of content.
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Calling back into ourselves for photo to transcode, optimizing the process (status: 302)
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - HTTP requesting to: http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Photo cache obtained 65338 bytes from http://127.0.0.1:35181/:/plugins/com.plexapp.plugins.aniverse/resources/icon-cover.png?t=1383235969
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Saving original media file to /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/80/80ba59f8fd587190bf08674fab58408515b034f1.jpg
Nov 05, 2013 15:49:18 [0xa3fffb70] DEBUG - Created thumbnail of size 512x512, has pixels: 1
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Request: HEAD /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53766] (9 live)
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - * height => 720
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - * width => 720
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:18 [0xa4cffb70] DEBUG - Content-Length of /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/01/0178d259fa75c78719783308361a77476b081746.jpg is 65714.
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Request: GET /photo/:/transcode?height=720&url=http%3a%2f%2f127.0.0.1%3a32400%2f%3a%2fplugins%2fcom.plexapp.plugins.aniverse%2fresources%2fcontentWithFallback%3ffallback%3dicon-cover.png%26urls%3dhttp%25253A%252F%252Faniverse.tv%252Fwp-content%252Fuploads%252F2013%252F08%252FAsu-No-Yoichi.png&width=720 [192.168.1.101:53767] (8 live)
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - * height => 720
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - * url => http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - * width => 720
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Request range: 0 to 0
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Photo transcoder: Request for url [127.0.0.1:32400/:/plugins/com.plexapp.plugins.aniverse/resources/contentWithFallback?fallback=icon-cover.png&urls=http%253A%2F%2Faniverse.tv%2Fwp-content%2Fuploads%2F2013%2F08%2FAsu-No-Yoichi.png] (is local: 1 upscaled: 0)
Nov 05, 2013 15:49:18 [0xac6ffb70] DEBUG - Content-Length of /mnt/cache/apps/Plex/Application Support/Plex Media Server/Cache/PhotoTranscoder/01/0178d259fa75c78719783308361a77476b081746.jpg is 65714.
```

---

<div class="post-metadata">

**Author:** ![shopgirl284](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shopgirl284](https://forums.plex.tv/u/shopgirl284)\
**Post date:** [November 5, 2013, 7:54pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/2 "2013-11-05T19:54:18Z")

</div>

I had one do that one time. When I took the fallback=icon.png out of the code, it found the image and worked fine.

```
So you would try changing:
thumb = Resource.ContentsOfURLWithFallback(url = show_thumb, fallback='icon-cover.png')
to:
thumb = Resource.ContentsOfURLWithFallback(url = show_thumb)
```

Not sure why this worked for me or what reason it caused an issue, but try it and see what happens.&nbsp;

And report back here if it makes a difference. I would be curious to know if others have encountered this and see if anyone knows the reason it happened.

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 5, 2013, 10:05pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/3 "2013-11-05T22:05:24Z")

</div>

Thanks for the reply. &nbsp;Unfortunately, it didn't work for me. &nbsp;It did however change my errors to 404's which I find strange. &nbsp;I guess it could be the ContentsOfURLWithFallback function reacting to not having a specified fallback though. &nbsp;Either way, I'm logging the url's its using and opening those url's in a browser work fine. &nbsp;I have to admit, it's got me puzzled. &nbsp; :wacko:

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [November 6, 2013, 3:13am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/4 "2013-11-06T03:13:24Z")

</div>

That sounds to me like the Resource.ContentsOfURLWithFallback() is failing to follow the redirect. I can’t think of a reason why it _shouldn’t_ follow redirects. Could be a bug. We’ll have to try to get @jam’s attention and see if there’s a reason that couldn’t/shouldn’t work of if it can be “fixed” in a future framework update.

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 6, 2013, 3:18am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/5 "2013-11-06T03:18:08Z")

</div>

OK cool. &nbsp;I'm still pretty new at this and I didn't want to be the first one to cry "bug" lol. &nbsp;In the meantime, is there anyway that I can work around it? &nbsp;I've seen mention somewhere of an undocumented arg for HTTP.Request to follow redirects? I know I can load my thumb in a separate function, can I use a HTTP request to follow the redirect, extract the image and return it that way? &nbsp;I'm sure I've seen something like this used in the official plugins but can't for the life of me remember where.

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [November 6, 2013, 5:57pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/6 "2013-11-06T17:57:57Z")

</div>

Can we have a look at the code and try the channel? I have a feeling this is more of a weird cache issue than it is a redirect issue. When I download the image without a Referer, User-Agent, etc header it's still working and there aren't any redirects.

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 6, 2013, 11:28pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/7 "2013-11-06T23:28:37Z")

</div>

I'd LOVE for someone to take a look at it. &nbsp;On top of this image issue, &nbsp;my code seems to be crashing PMC on Windows (I have a feeling both issues are related). &nbsp;However the same code works fine on PHT and Android. &nbsp;I've uploaded the plugin [HERE](https://drive.google.com/file/d/0ByaxMHEvJ7_oMFFKbHZxNktvQUk/edit?usp=sharing). &nbsp;It's on google drive so you'll need to hit File \> Download. &nbsp;Also, the plugin isn't actually functional yet, I have no URL service etc. &nbsp;I've hit this issue just trying to setup the navigation.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [November 7, 2013, 12:42pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/8 "2013-11-07T12:42:42Z")

</div>

Hi&nbsp;TehCrucible!

Thanks for the link, I checked out the channel and the images are working fine on my machine (tested with PMC, P/HT and Plex/Web). I think that you're looking at a caching problem and that something has gone wrong while you were developing your channel. Can you try the following to see if this fixes the problem on your machine?

- Close PMS

- Remove the contents of these folders (these are Mac paths, I don't have access to a Windows/Linux machine at the moment):

1. Depending on the version of Plex you have:  
 /Users//Library/Application Support/Plex/userdata/Thumbnails  
 or  
 /Users//Library/Application Support/Plex Home Theater/userdata/Thumbnails
2. /Users//Library/Caches/PlexMediaServer/PhotoTranscoder
3. /Users//Library/Application Support/Plex Media Server/Plug-in Support/Caches/com.plexapp.plugins.animeplus
4. /Users//Library/Application Support/Plex Media Server/Plug-in Support/Data/com.plexapp.plugins.animeplus

- Start PMS and try your channel again.

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 7, 2013, 1:07pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/9 "2013-11-07T13:07:59Z")

</div>

I'm so sorry, sander1. &nbsp;I linked you the wrong plugin!!! &nbsp; :wacko:

The plugin in question is actually [this one](https://drive.google.com/file/d/0ByaxMHEvJ7_obWFRVHo5YmQ1SnM/edit?usp=sharing). &nbsp;I did try removing the caches you suggested (including the correct plugin caches) but it hasn't helped unfortunately. &nbsp;Any chance I can get you to try out this one?! &nbsp;So sorry to waste your time.&nbsp;

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [November 7, 2013, 1:39pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/10 "2013-11-07T13:39:38Z")

</div>

Hey&nbsp;TehCrucible,

I checked your other channel, and I think the problem is the HTTP return status for the images, which is HTTP 200 No Error. A "normal" 200 status message is HTTP 200 OK. Other than that I cannot find anything wrong or different from other channels. I'm trying to contact the framework dev to see if this is a framework issue or a PMS issue.

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [November 7, 2013, 1:52pm UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/11 "2013-11-07T13:52:55Z")

</div>

A (temporary) solution could be to proxy the images with a service like, for example,&nbsp;images.weserv.nl:

```
# Remove http:// from the original URL when using images.weserv.nl.
http://images.weserv.nl/?url=www.animeplus.tv/images/series/small/1978.jpg
```

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [November 8, 2013, 1:02am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/12 "2013-11-08T01:02:09Z")

</div>

Hi!

I just noticed that in your code the wrong value is used for the thumbnail url.&nbsp;_show\_url_ is being used instead of&nbsp;_show\_thumb:_

```
thumb = Resource.ContentsOfURLWithFallback(url = show_url, fallback='icon-cover.png'),
```

**Edit:** &nbsp;Changing the value of url to _show\_thumb_ doesn't make work however :(

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [November 8, 2013, 3:28am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/13 "2013-11-08T03:28:12Z")

</div>

Haha thnks mate, I had also noticed and changed this one since. I’ll try out your proxy idea tonight. Thanks again for all your help. Originally I started this plugin as an experiment but it turns out the source site actually has a fair amount of metadata available with only the one http request so it would be good to get it working properly.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 21, 2019, 12:23am UTC](https://forums.plex.tv/t/dealing-with-image-redirects/46160/14 "2019-12-21T00:23:59Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
