I’ve searched a lot for a solution of this simple looking problem. I found a lot of irritating and confusing information about this on the WWW. From implementing a socket-application to setting up an self-made HTTP-server. But the answer is much simpler:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# enable debugging
import sys
import cgitb
import os.path
cgitb.enable()
if os.path.exists('maintenance.html'):
try:
templateFile = open('maintenance.html')
print '''Status:503
Content-type: text/html; charset=utf-8
Retry-After: 300
'''
print templateFile.read()
except IOError , e:
print("({})".format(e))
except ValueError:
print "Could not convert data to an integer."
except:
print "Unexpected error:", sys.exc_info()[0]
raise
The empty line after the “Retry-After” Header is very important!
