-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_v2.py
More file actions
32 lines (27 loc) · 820 Bytes
/
Copy pathserver_v2.py
File metadata and controls
32 lines (27 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
class Serv(http.server.SimpleHTTPRequestHandler):
def _set_response(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
if self.path == '/':
self.path = 'index.html'
try:
f = open(self.path[1:])
file_to_open = f.read()
self.send_response(200)
except:
file_to_open = "File not found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))
try:
f.close()
except:
pass
httpd = socketserver.TCPServer(("", PORT), Serv)
httpd.serve_forever()