Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
46 lines (38 loc) · 1.56 KB

File metadata and controls

46 lines (38 loc) · 1.56 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# Author: James Campbell
# Date: May 23rd 2016
# Date Updated: June 8th 2016
# What: Starts a http server as an example (works in Python 3)
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
# default unless set at prompt
hostPort = 10010
customPort = input("Default port 10010, hit enter or type custom one now: ")
if customPort != '':
hostPort = int(customPort)
hostName = "localhost"
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(
bytes("<html><head><title>MY PYTHON WEB SERVER PAGE!</title></head>", "utf-8"))
self.wfile.write(
bytes("<body style='font-family:monospace;'><p>This is a test.</p>", "utf-8"))
# you can use if else to check path and do custom things based on path accessed
if self.path == '/win':
self.wfile.write(bytes("<p>YOU WIN! @ path %s</p>" % self.path, "utf-8"))
else:
self.wfile.write(bytes("<p>You accessed path: %s</p>" % self.path, "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
# continue to serve until a keypress in terminal
try:
myServer.serve_forever()
except KeyboardInterrupt:
pass
myServer.server_close()
print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))
# python3 -m http.server 10010 --bind 127.0.0.1
Morty Proxy This is a proxified and sanitized view of the page, visit original site.