simplehttpserver


Python SimpleHTTPServer: change response header

断了今生、忘了曾经 提交于 2020-01-25 11:11:11
问题 I use python's SimpleHTTPServer for tests applications. Now for the test I need to change in the server response header field "Server". Now I have "Server: SimpleHTTP/0.6 Python/2.7.3" I would like something like "Server: Apache123". Is it possible to change this field? Thx. 回答1: If you wanted to have something easy to edit you could use this: import SimpleHTTPServer import BaseHTTPServer def main(): request_handler = SimpleHTTPServer.SimpleHTTPRequestHandler request_handler.server_version =

Embedded Web Server in Python? [closed]

帅比萌擦擦* 提交于 2020-01-22 09:42:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Can you recommend a minimalistic python webserver that I can embedded in my Desktop Application. 回答1: How minimalistic and for what purpose? SimpleHTTPServer comes free as part of the standard Python libraries. If you need more features, look into CherryPy or (at the top end) Twisted. 回答2: I'm becoming a big fan

Embedded Web Server in Python? [closed]

≡放荡痞女 提交于 2020-01-22 09:42:52
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Can you recommend a minimalistic python webserver that I can embedded in my Desktop Application. 回答1: How minimalistic and for what purpose? SimpleHTTPServer comes free as part of the standard Python libraries. If you need more features, look into CherryPy or (at the top end) Twisted. 回答2: I'm becoming a big fan

How to use Content-Encoding: gzip with Python SimpleHTTPServer

人走茶凉 提交于 2020-01-03 08:48:10
问题 I'm using python -m SimpleHTTPServer to serve up a directory for local testing in a web browser. Some of the content includes large data files. I would like to be able to gzip them and have SimpleHTTPServer serve them with Content-Encoding: gzip. Is there an easy way to do this? 回答1: Since this was the top google result I figured I would post my simple modification to the script that got gzip to work. https://github.com/ksmith97/GzipSimpleHTTPServer 回答2: This is an old question, but it still

Print statements not working when serve_forever() is called?

早过忘川 提交于 2020-01-01 06:57:05
问题 I have the following small python script to run a local server for testing some html: print('opened') from http.server import HTTPServer, SimpleHTTPRequestHandler server_address = ('', 8000) httpd = HTTPServer(server_address, SimpleHTTPRequestHandler) print("Listening at https://127.0.0.1:8000/ . . .") httpd.serve_forever() When I run this in the terminal, it blocks the print statements: nothing is printed. But the server works and I can go to localhost:8000 in the browser and access my html

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

一曲冷凌霜 提交于 2019-12-28 01:38:11
问题 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. 回答1: 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

SimpleHTTPServer in Python3.6.4 can not handle non-ASCII string(Chinese in my case)

本秂侑毒 提交于 2019-12-24 16:16:04
问题 I run SimpleHTTPServer in Python3.6.4 64bit by this command: python -m http.server --cgi then I make a form in test.py, submit it to test_form_action.py to print the input text. cgi-bin/test.py # coding=utf-8 from __future__ import unicode_literals, absolute_import print("Content-Type: text/html") # HTML is following print() reshtml = '''<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/> </head> <body> <div style="text-align: center;"

Local server giving wrong files. Is it possible I'm running 2 python servers?

只愿长相守 提交于 2019-12-23 03:54:26
问题 I'm in the directory /backbone/ which has a main.js file within scripts. I run python -m SimpleHTTPServer from the backbone directory and display it in the browser and the console reads the error $ is not defined and references a completely different main.js file from something I was working on days ago with a local python server. I am new to this and don't have an idea what's going on. Would love some suggestions if you have time. 回答1: Only one process can listen on a port; you cannot have

Shutting down python TCPServer by custom handler

橙三吉。 提交于 2019-12-22 12:34:38
问题 I'm trying to shutdown a TCPServer from the SocketServer module through a GET request by the client, emitted when the window is closed, however the following code fails to initiate the shutdown: def show_webgl(data): import SocketServer import SimpleHTTPServer from webbrowser import open PORT = 8000 RUNNING = True class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): if self.path=='/atom.json': # return data return elif self.path == '/shutdown': httpd.shutdown() #

How do I kill SimpleHTTPServer from within a Python script?

。_饼干妹妹 提交于 2019-12-21 12:09:17
问题 I am trying to use http.server to test all the links in a Python project. I can get my script to work if I start the server before running my script, and then the server stops when I close the terminal window. But I'd really like the script itself to start and stop the server. I made a test script to simply start the server, get a page and prove the server is running, and then stop the server. I can't seem to get the pid of the server. When I try to kill the pid that this script reports after

工具导航Map