我编写了一个简单的程序来渲染请求国家的国旗 svg 图像。为了确保图像存在,我想先检查一下。但是,我得到以下异常: HTTPException: Deadline exceeded while waiting for HTTP response from URL: http://localhost:8087/images/flag_images/Flag_of_Nepal.svg
无论我为超时设置的值如何,都会发生这种情况。不能用相同的端口调用内部服务器吗?顺便说一句,我正在使用 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