0

I have written a simple program to render requested country's svg image of Flag. To make sure that the image exists I want to check first. However, I get following exception: HTTPException: Deadline exceeded while waiting for HTTP response from URL: http://localhost:8087/images/flag_images/Flag_of_Nepal.svg

This occurs regardless of the value I set for timeout. Is it not possible to make a call to internal server with same port? BTW I am using GAE.

class backbone(Handler):
def render_front(self):
    User_id = self.request.cookies.get('user_id')
    if User_id:
        Valid_User = check_secure_val(User_id)
        if Valid_User:
            p  = UserAccount.get_by_id(int(Valid_User))
            User = p.User
        else:
            User = ""
    else:
        User = ""
    self.render("backbone.html", image = "")


def get(self):
    self.render_front()

def post(self):
    a = self.request.get('country')
    image = self.exists('localhost', 8087, ("/images/flag_images/Flag_of_%s.svg" %a))
    if image:
        self.render('backbone.html', image = '<img src = "/images/flag_images/Flag_of_%s.svg" alt="" width="60" height="45"/>'  % a)    
    else:
        self.render('backbone.html', image = '<img src = "/images/flag_images/NoFlag.svg" alt="" width="60" height="45"/>'  % a)    


def exists(self, site, port, path):
    conn = httplib.HTTPConnection(site, port, timeout= 40)
    conn.request('GET', path)
    response = conn.getresponse()
    conn.close()
    return response.status == 200
Cœur
  • 37,241
  • 25
  • 195
  • 267
Oo.oO
  • 33
  • 3

1 Answers1

0

You can't use localhost like that with GAE. You'll need an external URL reference. If you are trying to fetch images from your local machine to GAE, you'll need to open that port on your router, see http://portforward.com/ and then plug your IP address in as gotten from https://www.google.com/?q=what+is+my+ip as the url. E.g. for me it would be something like http://67.84.162.157:8000/images/usa.svg

Matt Williamson
  • 39,165
  • 10
  • 64
  • 72
  • Thank you. Is there any other way to check if any other way to check if a static file is present or not? – Oo.oO Nov 30 '12 at 03:29