Questions tagged [basehttpserver]

This Python class is used to make a simple HTTP web server.

Related links

126 questions
72
votes
1 answer

How to silent/quiet HTTPServer and BasicHTTPRequestHandler's stderr output?

I am writing a simple http server as part of my project. Below is a skeleton of my script: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class MyHanlder(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) …
Hai Vu
  • 37,849
  • 11
  • 66
  • 93
68
votes
1 answer

How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?

In the do_POST() method of BaseHTTPRequestHandler I can access the headers of the POST request simply via the property self.headers. But I can't find a similar property for accessing the body of the message. How do I then go about doing that?
G S
  • 35,511
  • 22
  • 84
  • 118
67
votes
11 answers

How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?

I am running my HTTPServer in a separate thread (using the threading module which has no way to stop threads...) and want to stop serving requests when the main thread also shuts down. The Python documentation states that BaseHTTPServer.HTTPServer…
Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
66
votes
4 answers

Python 3.x BaseHTTPServer or http.server

I am trying to make a BaseHTTPServer program. I prefer to use Python 3.3 or 3.2 for it. I find the doc hard to understand regarding what to import but tried changing the import from: from BaseHTTPServer import…
Learner
  • 661
  • 1
  • 5
  • 4
39
votes
5 answers

Parse http GET and POST parameters from BaseHTTPHandler?

BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body? Right now,…
ataylor
  • 64,891
  • 24
  • 161
  • 189
21
votes
1 answer

What is the difference between BaseHTTPServer and SimpleHTTPServer? When and where to use them?

What is the difference between BaseHTTPServer and SimpleHTTPServer? When and where should I use these?
Sriram
  • 1,180
  • 2
  • 15
  • 27
19
votes
6 answers

BaseHTTPRequestHandler with custom instance

this is my http server: from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer class test: def show(self): return "aaaa" class http_server: def __init__(self, t1): self.t1 = t1 server = HTTPServer(('', 8080),…
16
votes
3 answers

Python BaseHTTPServer, how do I catch/trap "broken pipe" errors?

I build a short url translator engine in Python, and I'm seeing a TON of "broken pipe" errors, and I'm curious how to trap it best when using the BaseHTTPServer classes. This isn't the entire code, but gives you an idea of what I'm doing so far: …
iandouglas
  • 4,146
  • 2
  • 33
  • 33
15
votes
4 answers

Python: BaseHTTPRequestHandler - Read raw post

How do I read the raw http post STRING. I've found several solutions for reading a parsed version of the post, however the project I'm working on submits a raw xml payload without a header. So I am trying to find a way to read the post data without…
kwolfe
  • 1,663
  • 3
  • 17
  • 27
13
votes
6 answers

Daemonizing python's BaseHTTPServer

I am working on a daemon where I need to embed a HTTP server. I am attempting to do it with BaseHTTPServer, which when I run it in the foreground, it works fine, but when I try and fork the daemon into the background, it stops working. My main…
Gavin M. Roy
  • 4,551
  • 4
  • 33
  • 29
13
votes
1 answer

Serve a file from Python's http.server - correct response with a file

I am simply trying to serve a PDF file from the http.server. Here is my code: from http.server import BaseHTTPRequestHandler, HTTPServer class MyServer(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) …
Clone
  • 3,378
  • 11
  • 25
  • 41
13
votes
2 answers

Run Python HTTPServer in Background and Continue Script Execution

I am trying to figure out how to run my overloaded customized BaseHTTPServer instance in the background after running the "".serve_forever() method. Normally when you run the method execution will hang until you execute a keyboard interrupt, but I…
13
votes
1 answer

Python - BaseHTTPServer.HTTPServer Concurrency & Threading

Is there a way to make BaseHTTPServer.HTTPServer be multi-threaded like SocketServer.ThreadingTCPServer?
Ian
  • 24,116
  • 22
  • 58
  • 96
12
votes
2 answers

Stuck with Python HTTP Server with Basic Authentication using BaseHTTP

I am stuck trying to get a python based webserver to work. I want to do Basic Authentication (sending a 401 header) and authenticating against a list of users. I have no trouble sending the 401 response with "WWW-Authorize" header, I can validate…
Alexander
  • 121
  • 1
  • 1
  • 3
11
votes
3 answers

Python BaseHTTPRequestHandler: Respond with JSON

I have a Python class that inherits BaseHTTPRequestHandler and implements the method do_POST. I currently only succeed to respond with an integer status, e.g. 200, using the following command at the end of the method: self.send_response(200) I am…
SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
1
2 3
8 9