I have created a Google AppEngine Project which takes in a .txt file, finds locations within the file and uses Yahoo Placemaker to plot a maker on the map to represent the .txt file.
The project works fine when I run in on my localhost but when I try and upload it to appspot I get an error:
BadValueError: Property lat must be a float
My main.py looks like this:
class Story(db.Model):
id = db.StringProperty()
loc_name = db.StringProperty()
title = db.StringProperty()
lat = db.FloatProperty()
long = db.FloatProperty()
link = db.StringProperty()
class MyStories(webapp.RequestHandler):
def get(self):
temp = db.Query(Story)
temp = temp.count()
story_set = Story.all()
template_values = {
'storyTemp': story_set
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class place(webapp.RequestHandler):
def get(self):
path = '/Users/kimmasterson/storing/txtFiles'
try:
for infile in glob.glob(os.path.join(path, '*.txt')):
#print infile
f = open(infile, 'r')
data = f.read()
newfile = infile.replace('.txt', '')
newfile = newfile.replace('/Users/kimmasterson/storing/txtFiles/', '')
#print newfile
storyname = 'http://www.independent.ie/national-news/' + newfile
#print storyname
#print newfile
#logging.info(data)
p = placemaker('HSnG9pPV34EUBcexz.tDYuSrZ8Hnp.LowswI7TxreF8sXrdpVyVIKB4uPGXBYOA9VjjF1Ca42ipd_KhdJsKYjI5cXRo0eJM-')
print p.find_places(data)
for place in p.places:
splitted = place.name.split()
for word in splitted:
temp = db.Query(Story)
temp = temp.filter("link = ", storyname)
results = temp.fetch(limit=1)
if len(results) >0:
break
elif 'IE' in word:
print temp
print 'success'
story = Story(name=newfile, lat=place.centroid.latitude, long=place.centroid.longitude, link=storyname, loc_name = place.name, title = newfile).put()
except:
print 'error'
logging.info('BIG FAT ERROR')
def main():
application = webapp.WSGIApplication([('/', MyStories), ('/place', place)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
My cron.yaml:
cron:
- description: running place
url: /place
schedule: every day 10:00
For some reason it adds the places and links the file to the map on my localhost. Any ideas how the same code in both places can work in one and not in the other?
The obvious answer is that
lat(which you’re getting fromplace.centroid.latitude) isn’t a float. Try loggingtype(place.centroid.latitude)to see what type it is – my guess would be that it’s a string, and you’ll need to callfloat()on it to parse it.As @Thomas points out, you obviously can’t refer to a file on your local machine and expect it to work once uploaded to App Engine. Instead, put your static data inside your app’s root directory (or a subdirectory), and open it with a relative path. The easiest and most robust way to do that is like this: