Reputation: 85
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import urlfetch
class TrakHtml(db.Model):
hawb = db.StringProperty(required=False)
htmlData = db.TextProperty()
class MainHandler(webapp.RequestHandler):
def get(self):
Traks = list()
Traks.append('93332134')
#Traks.append('91779831')
#Traks.append('92782244')
#Traks.append('38476214')
for st in Traks :
trak = TrakHtml()
trak.hawb = st
url = 'http://etracking.cevalogistics.com/eTrackResultsMulti.aspx?sv='+st
result = urlfetch.fetch(url)
self.response.out.write(result.read())
***trak.htmlData = result.read()
trak.put()
#self.response.out.write(st)
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
I am getting error at ***line it is not reading url data.
Upvotes: 0
Views: 574
Reputation: 70344
You have read the result twice (once in self.responce.out.write
and once a line below).
Store the value as a string first:
htmlData = result.read()
self.response.out.write(htmlData)
trak.htmlData = htmlData
I would expect result.read()
to move to the end of the result
stream - think of it like a book: Reading a book, you flip page by page. When you get to the end, trying to read gets difficult - unless you rewind to the beginning.
Also, please state the error message - that is often a tremendous help in diagnosing a problem!
Upvotes: 3