else/ServerReference/simpleserver.py

22 lines
553 B
Python
Raw Normal View History

2015-09-03 21:09:35 +00:00
import http.server
f = open('favicon.png', 'rb')
FAVI = f.read()
f.close()
class RequestHandler(http.server.BaseHTTPRequestHandler):
def write(self, string):
if isinstance(string, str):
string = string.encode('utf-8')
self.wfile.write(string)
def do_GET(self):
#print(dir(self))
print(self.path)
if self.path == '/favicon.ico':
self.write(FAVI)
self.write('heyo')
server = http.server.HTTPServer(('', 80), RequestHandler)
print('server starting')
server.serve_forever()