Questions tagged [basehttprequesthandler]

74 questions
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
42
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
  • 13,574
  • 2
  • 45
  • 55
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),…
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
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
9
votes
4 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,859
  • 5
  • 20
  • 21
8
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
6
votes
1 answer

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,888
  • 5
  • 32
  • 61
6
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…
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
  • 4,798
  • 3
  • 21
  • 35
5
votes
2 answers

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…
4
votes
0 answers

variables inside BaseHTTPRequestHandler Python

I am creating a chatbot using Python and MS Bot Builder SDK for Python. The bot is a HTTPServer using a handler. What I want are variables to help me keeping track of the conversation, for example a message counter. But I can't get it to work, each…
Yann Droy
  • 177
  • 1
  • 2
  • 9
4
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
  • 387
  • 1
  • 3
  • 12
4
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
  • 6,214
  • 12
  • 64
  • 132
3
votes
1 answer

How to parse POST data into a dictionary

I'm trying to write a simple "server" that inherits from BaseHTTPRequestHandler and is able to receive GET and POST requests. I have a server.py file that, so far, looks like this: from http.server import BaseHTTPRequestHandler, HTTPServer from cgi…
Tuma
  • 603
  • 1
  • 7
  • 35
1
2 3 4 5