Questions tagged [basehttprequesthandler]

73 questions
54
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?
Frederick The Fool
  • 31,355
  • 20
  • 78
  • 112
32
votes
4 answers

Writing response body with BaseHTTPRequestHandler

I'm playing a little with Python 3.2.2 and want to write a simple web server to access some data remotely. This data will be generated by Python so I don't want to use the SimpleHTTPRequestHandler as it's a file server, but a handler of my own. I…
helios
  • 12,916
  • 2
  • 41
  • 51
17
votes
5 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),…
13
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,607
  • 2
  • 12
  • 27
9
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
  • 9,410
  • 12
  • 56
  • 105
8
votes
3 answers

How do you override BaseHTTPRequestHandler log_message() method to log to a file rather than to console (sys.stderr)?

I'm creating a Webservice using BaseHTTPServer.HTTPServer I would like to log the following to be logged to a file rather than to the console. But I have not managed to find a way to do so yet. 10.23.23.19 - - [29/Nov/2013 08:39:06] "GET / HTTP/1.1"…
Phil
  • 2,219
  • 3
  • 16
  • 21
6
votes
0 answers

Add a new instance variable to subclass of http.server.BaseHTTPRequestHandler

I want to be able to add an instance variable to my subclass of http.server.BaseHTTPRequestHandler. Here's my code: from http.server import BaseHTTPRequestHandler, HTTPServer import urllib class Server(BaseHTTPRequestHandler): def…
cat
  • 3,442
  • 3
  • 28
  • 55
6
votes
2 answers

How do I access the data sent to my server using BaseHTTPRequestHandler?

I'm a newbie to Python (using v3.3) and web programing and I've been struggling with a problem all night. I'm issuing a POST call to my server and sending it some data as follows: DATA = {"listName":"Test list","listDesc":"A test list with test…
Ben
  • 3,204
  • 3
  • 15
  • 24
5
votes
1 answer

BaseHTTPRequestHandler hangs on self.rfile.read()

I implemented a python server using the BaseHTTPRequestHandler and it, often times, will hang while reading from the socket fileobject. It doesnt seem to matter how many bytes I read. I could read 30k bytes and it wont hang or I could read 7k bytes…
5
votes
1 answer

Redirect function with BaseHTTPRequestHandler

This is my code: from http.server import HTTPServer, BaseHTTPRequestHandler class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/html') …
user3241727
4
votes
0 answers

How to call function from Python HTTP server?

I want to provide one of my applications with a web interface. To achieve that, I subclass BaseHTTPRequestHandler from the BaseHTTPServer package (into a class I call _RequestHandler) and implement my own handlers for HTTP HEAD / GET / POST / PUT…
3
votes
1 answer

Why is do_GET much faster than do_POST

Python's BaseHTTPRequestHandler has an issue with forms sent through post! I have seen other people asking the same question (Why GET method is faster than POST?), but the time difference in my case is too much (1 second) Python server: from…
user34812
  • 483
  • 1
  • 3
  • 12
3
votes
2 answers

python - using BaseHTTPRequestHandler with UnixStreamServer causes exception

I'm trying to create a basic HTTP server bound to a Unix Domain Socket, but using a BaseHTTPRequestHandler subclass with UnixStreamServer is creating an exception that suggests they cannot work together. Toy server.py: from SocketServer import…
mrjogo
  • 337
  • 2
  • 11
3
votes
1 answer

How to transfer images to client using Python BaseHttpRequestHandler in Windows?

I know that this question has already been asked before, for instance here: How do I serve image Content-types with Python BaseHTTPServerRequestHandler do_GET method?, but the typical answer of "set your file open mode to binary" is not working for…
RTF
  • 5,332
  • 8
  • 47
  • 104
2
votes
1 answer

How to know using BaseHTTPRequestHandler that client closed connection

I am writing http server that can serve big files to client. While writing to wfile stream it is possible that client closes connection and my server gets socket error (Errno 10053). Is it possible to stop writing when client closes connection?
Dmitrii Tokarev
  • 137
  • 2
  • 9
1
2 3 4 5