simplehttpserver

Is it possible to run python SimpleHTTPServer on localhost only?

故事扮演 提交于 2019-11-27 10:31:18
I have a vpn connection and when I'm running python -m SimpleHTTPServer, it serves on 0.0.0.0:8000, which means it can be accessed via localhost and via my real ip. I don't want robots to scan me and interested that the server will be accessed only via localhost. Is it possible? python -m SimpleHTTPServer 127.0.0.1:8000 # doesn't work. Any other simple http server which can be executed instantly using the command line is also welcome. If you read the source you will see that only the port can be overridden on the command line. If you want to change the host it is served on, you will need to

socket.error: [Errno 48] Address already in use

女生的网名这么多〃 提交于 2019-11-27 09:56:39
I'm trying to set up a server with python from mac terminal. I navigate to folder location an use: python -m SimpleHTTPServer But this gives me error: socket.error: [Errno 48] Address already in use I had previously open a connection using the same command for a different website in a different location in my machine. You already have a process bound to the default port (8000). If you already ran the same module before, it is most likely that process still bound to the port. Try and locate the other process first: $ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m

How do I shut down a python simpleHTTPserver?

筅森魡賤 提交于 2019-11-27 09:15:46
问题 So I'm trying to learn d3, and the wiki suggested that To view the examples locally, you must have a local web server. Any web server will work; for example you can run Python's built-in server: python -m SimpleHTTPServer 8888 & Great... only now I have a server running... but at some point I think I should probably shut that down again. Is there a better way of shutting it down than using kill <pid> ? That seems like kind of a big hammer for a little job. (I'm running Mac OS 10.6.8 (Snow

Enable access control on simple HTTP server

杀马特。学长 韩版系。学妹 提交于 2019-11-27 09:12:00
问题 I have the following shell script for a very simple HTTP server: #!/bin/sh echo "Serving at http://localhost:3000" python -m SimpleHTTPServer 3000 I was wondering how I can enable or add a CORS header like Access-Control-Allow-Origin: * to this server? 回答1: Unfortunately, the simple HTTP server is really that simple that it does not allow any customization, especially not for the headers it sends. You can however create a simple HTTP server yourself, using most of SimpleHTTPRequestHandler ,

Can I set a header with python's SimpleHTTPServer?

眉间皱痕 提交于 2019-11-27 07:45:12
I'm using SimpleHTTPServer to test some webpages I'm working on. It works great, however I need to do some cross-domain requests. That requires setting a Access-Control-Allow-Origin header with the domains the page is allowed to access. Is there an easy way to set a header with SimpleHTTPServer and serve the original content? The header would be the same on each request. berto This is a bit of a hack because it changes end_headers() behavior, but I think it's slightly better than copying and pasting the entire SimpleHTTPServer.py file. My approach overrides end_headers() in a subclass and in

Reading JSON from SimpleHTTPServer Post data

北城余情 提交于 2019-11-27 07:05:38
I am trying to build a simple REST server with python SimpleHTTPServer. I am having problem reading data from the post message. Please let me know if I am doing it right. from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer import simplejson class S(SimpleHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() def do_GET(self): print "got get request %s" % (self.path) if self.path == '/': self.path = '/index.html' return SimpleHTTPRequestHandler.do_GET(self) def do_POST(self): print "got post!!"

How to run a http server which serves a specific path?

有些话、适合烂在心里 提交于 2019-11-27 05:27:41
问题 this is my Python3 project hiearchy: projet \ script.py web \ index.html From script.py , I would like to run a http server which serve the content of the web folder. Here is suggested this code to run a simple http server: import http.server import socketserver PORT = 8000 Handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", PORT), Handler) print("serving at port", PORT) httpd.serve_forever() but this actually serve project , not web . How can I specify the path

How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?

点点圈 提交于 2019-11-27 02:11:16
问题 When I run python -m SimpleHTTPServer 8000 or python -m CGIHTTPServer 8000 in my shell I am hosting the content of my current directory to the internet. I would like to make the following cgi_script.py work correctly using the above command in the command line when I browse to 192.xxx.x.xx:8000/cgi_script.py #!/usr/bin/env python print "Content-Type: text/html" print print """\ <html> <body> <h2>Hello World!</h2> </body> </html> """ But this script is displayed literally and not only the

What is the Python 3 equivalent of “python -m SimpleHTTPServer”

久未见 提交于 2019-11-26 21:12:15
What is the Python 3 equivalent of python -m SimpleHTTPServer ? From the docs : The SimpleHTTPServer module has been merged into http.server in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0. So, your command is python -m http.server , or depending on your installation, it can be: python3 -m http.server The equivalent is: python3 -m http.server Using 2to3 utility. $ cat try.py import SimpleHTTPServer $ 2to3 try.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit

Reading JSON from SimpleHTTPServer Post data

余生长醉 提交于 2019-11-26 17:37:16
问题 I am trying to build a simple REST server with python SimpleHTTPServer. I am having problem reading data from the post message. Please let me know if I am doing it right. from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer import simplejson class S(SimpleHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() def do_GET(self): print "got get request %s" % (self.path) if self.path == '/': self