Answers for "create server in python"

16

start a simple http server python3

python3 -m http.server 8000
Posted by: Guest on November-30-2020
4

python httpserver

python -m http.server 8000 --bind 127.0.0.1
Posted by: Guest on March-31-2020
2

create a server in python

# Python 3 server example
from http.server 
import BaseHTTPRequestHandler, HTTPServer
import time
hostName = "localhost"
serverPort = 8080
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>https://pythonbasics.org</title></head>", "utf-8"))
        self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
        self.wfile.write(bytes("<body>", "utf-8"))
        self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
        self.wfile.write(bytes("</body></html>", "utf-8"))
    if __name__ == "__main__":
    	webServer = HTTPServer((hostName, serverPort), MyServer)
        print("Server started http://%s:%s" % (hostName, serverPort))
        try:
        webServer.serve_forever()
        except KeyboardInterrupt:
        pass
        webServer.server_close()
        print("Server stopped.")
Posted by: Guest on May-21-2021
4

python http server command line

python -m SimpleHTTPServer
Posted by: Guest on June-29-2020
4

python local server command

On Ubuntu go to Commands and hit these two commands->
cd folderName
python3 -m http.server 8080
Posted by: Guest on April-29-2020
1

server on python

import http.server
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("serving at port", PORT)
    httpd.serve_forever()
Posted by: Guest on May-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language