I get this error when trying to get the height of an image:
'Image' object has no attribute 'height': Traceback (most recent call last): File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~montaoproject/2013b.368090623852761997/main.py",
Why? It is an image object so it should have height. What I'm trying to do is just
height = image.height
The full class in google app engine is
class NewAdHandler(BaseHandler):
def get_ad(self, key):
data = memcache.get(key)
if data is not None:
return data
else:
data = Ad.get_by_id(long(key))
memcache.add(key, data, 6000)
return data
def get_image(self, ad):
data = memcache.get(str(ad.key()))
if data is not None:
return data
else:
data = ad.matched_images.get()
memcache.add(str(ad.key()), data, 6000)
return data
def get_images(self, ad):
data = memcache.get(str(ad.key()) + 'images')
if data is not None:
return data
else:
data = ad.matched_images
memcache.add(str(ad.key()) + 'images', data, 6000)
return data
def get(self, id, html):
logging.debug('logged in %s', self.logged_in)
region = None
city = None
ad = self.get_ad(id)
if not ad or not ad.published:
self.error(404)
return
image = self.get_image(ad)
#height = image.height
#logging.debug('height %d', height)
url = self.request.url
image_url = None
country = ''
if self.request.host.find('koolbusiness.com') > -1: country = 'India'
elif self.request.host.find('montao.com') > -1: country = 'Brasil'
elif self.request.host.find('hipheap.com') > -1: country = 'USA'
if image:
if image.primary_image:
try:
image_url = \
images.get_serving_url(str(image.primary_image.key()),
size=640)
thumb_url = \
images.get_serving_url(str(image.primary_image.key()),
size=120)
except Exception, e:
image_url = '/images/' + str(image.key().id()) \
+ '_small.jpg'
else:
image_url = '/images/' + str(image.key().id()) \
+ '_small.jpg'
imv = []
for i in self.get_images(ad):
if i.primary_image:
try:
i1 = \
images.get_serving_url(str(i.primary_image.key()))
imv.append(i1)
except Exception, e:
i1 = '/images/' + str(image.key().id()) \
+ '_small.jpg'
imv.append(i1)
price = ad.price
if ad.geopt and not ad.city:
logging.info('geopt:' + str(ad.geopt))
url = 'http://maps.googleapis.com/maps/api/geocode/json' \
+ '?latlng={},{}&sensor=false'.format(ad.geopt.lat,
ad.geopt.lon)
result = urlfetch.fetch(url)
jsondata = json.loads(result.content)
for result in jsondata['results']:
for component in result['address_components']:
if 'administrative_area_level_1' \
in component['types']:
region = component['long_name'].replace('County'
, '')
if 'locality' in component['types']:
city = component['long_name']
if ad.city != city:
ad.city = city
ad.put()
if ad.region != region:
ad.region = region
ad.put()
if ad.price: # and doesn't contain separators
try:
price = \
i18n.I18n(self.request).format_decimal(int(ad.price))
except Exception, e:
price = ad.price
else:
city = ad.city
region = ad.region # if ad.region eller get region
if region == None:
region = ''
if region == None:
region = ''
regionentity = montaomodel.Region.all().filter('name =',
region).get()
cityentity = montaomodel.City.all().filter('name =', city).get()
logging.debug('is logged in: %s', self.logged_in,)
self.render_jinja(
'view_ad',
image_url=image_url,
region=ad.region,
regionentity=regionentity,
cityentity=cityentity,
city=city,country=country,
imv=imv,request=self.request,
len=len(imv),height=height,
ad=ad,thumb_url=thumb_url,
price=price,VERSION=VERSION,
#user_url=(users.create_logout_url(self.request.uri) if users.get_current_user() else None),
admin=users.is_current_user_admin(),
linebreak_txt=(ad.text.replace('\n', '<br>'
) if ad.text else None),
image=image,
user = self.current_user,
logged_in = self.logged_in,
form=AddAdCityForm(),
form_url=self.request.url,
)