I am trying to make a Web Application based on Google App Engine in python. A part of it deals with displaying the poster of Movie hosted at IMDb. I have the link to the poster. For ex.
http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1._SX94_SY140_.jpg
Then I tried to put it in an HTML page as:
<a href="https://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3.jpg">
<img src="https://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3.jpg">
</a>
The image isn;t shown and on clicking it, a page opens saying:
Referral Denied
You don't have permission to access "https://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3.jpg" on this server.
Reference #24.84d81002.1393249598.981ca7
On going through this question, I came to know that IMDb does not allow referrals to any other sites. The solution was to get the image yourself, save it and then serve it yourself. For doing that, I followed this link.
I made a datastore object storing various informations of the movie as well as the poster which was fetched using urlfetch api. relevant parts of the code are
from google.appengine.ext import db
from google.appengine.api import urlfetch
class Movie(db.Model):
title = db.StringProperty()
poster = db.BlobProperty(default=None)
coverurl = "https://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3.jpg"
movie = Movie()
posterimg = urlfetch.fetch(coverurl).content
movie.cover = db.Blob(posterimg)
movie.put()
Now, for rendering the html page, I got the movie object from datastore as
m = Movie.gql("WHERE title = :1", title).get()
img = m.posterimg
and the html page was rendered as
imghtml = ' <img src="' + img + '"> </a>'
An error was expected and was recieved as:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
What is the way out of this? How can I include an Image which is stored as a blob in Datastore in a html image?