Retrieve input

A

amfr

A little while ago, someone told me that for the BaseHTTPServer module,
the whole request would be stored in self.rfile.
I looked at the doumentation and is says rfile is:
"Contains an input stream, positioned at the start of the optional
input data."
How do i get the input out of it?
 
F

Fredrik Lundh

amfr said:
A little while ago, someone told me that for the BaseHTTPServer module,
the whole request would be stored in self.rfile.
I looked at the doumentation and is says rfile is:
"Contains an input stream, positioned at the start of the optional
input data."
How do i get the input out of it?

by reading from it, as you would read data from any other file:

http://docs.python.org/lib/bltin-file-objects.html

(the word "stream" usually refers to a file or file-like object. seeking
is usually not supported, and file-like objects may not implement all
the methods available on a "real" file object. the basics should work,
though: read, readline, etc.)

</F>
 
A

amfr

Thanks, but when I try to read the stream using read(), the script just
keeps on going and does not stop. When i press ctrl + c, the script
shows thsi (top of error taken off):
File "modules/runpython.py", line 88, in runModule
sys.stdin = self.rfile.read()
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/socket.py",
line 283, in read
data = self._sock.recv(recv_size)
KeyboardInterrupt

Any ideas?
 
P

Peter Hansen

amfr said:
Thanks, but when I try to read the stream using read(), the script just
keeps on going and does not stop. When i press ctrl + c, the script
shows thsi (top of error taken off):
File "modules/runpython.py", line 88, in runModule
sys.stdin = self.rfile.read()
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/socket.py",
line 283, in read
data = self._sock.recv(recv_size)
KeyboardInterrupt

Any ideas?

It's connecting to a server, and trying to grab all the data... but the
server isn't sending anything at this point, so the call to _sock.recv()
blocks indefinitely.

Troubleshooting further would require details you haven't provided, such
as what URL is requested, what the server is, etc...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top