Skip to content

Instantly share code, notes, and snippets.

@fr3aker
Last active August 29, 2015 14:07
Show Gist options
  • Save fr3aker/d8e22f63d910c85b7f0d to your computer and use it in GitHub Desktop.
Save fr3aker/d8e22f63d910c85b7f0d to your computer and use it in GitHub Desktop.
very simple http maintenance server
#!/usr/bin/env python3
import http.server
def createHandler(message=None, content=None):
errnum = 503
class ErrorHandler(http.server.BaseHTTPRequestHandler):
error_message_format = """\
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>%(message)s</title>
</head>
<body>
<h1>%(message)s</h1>
<p>%(explain)s</p>
"""
def handle_one_request(self):
self.responses[errnum] = (message, content)
self.requestline = ''
self.request_version = ''
self.command = ''
self.send_error(errnum)
return ErrorHandler
if __name__ == "__main__":
server_address = ('', 8000)
try:
with open("error.txt") as f:
errtext = f.read()
except:
errtext = "Diese Seite ist in Kürze wieder verfügbar."
handler = createHandler("Wartungsarbeiten", errtext)
httpd = http.server.HTTPServer(server_address, handler)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment