Deliver status 503 with you Python CGI-script

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:

# -*- coding: UTF-8 -*-
# enable debugging
import sys
import cgitb
import os.path

if os.path.exists('maintenance.html'):
        templateFile = open('maintenance.html')
        print '''Status:503
Content-type: text/html; charset=utf-8
Retry-After: 300

    except IOError , e:
    except ValueError:
        print "Could not convert data to an integer."
        print "Unexpected error:", sys.exc_info()[0]

The empty line after the “Retry-After” Header is very important!

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.