tags:

views:

60

answers:

1
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


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. please help me

+3  A: 

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!

Daren Thomas