I could see a couple of examples to read from the http stream. But how to write to a http input stream using python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use standard library module httplib: in the HTTPConnection.request method, the
bodyargument (since Python 2.6) can be an open file object (better be a “pretty real” file, since, as the docs say, “this file object should support fileno() and read() methods”; but it could be a named or unnamed pipe to which a separate process can be writing). The advantage is however dubious, since (again per the docs) “The header Content-Length is automatically set to the correct value” — which, since headers come before body, and the file’s content length can’t be known until the file is read, implies the whole file’s going to be read into memory anyway.If you’re desperate to “stream” dynamically generated content into an
HTTPPOST(rather than preparing it all beforehand and then posting), you need a server supporting HTTP’s “chunked transfer encoding”: this SO question‘s accepted answer mentions that the popular asynchronous networking Python packagetwisteddoes, and gives some useful pointers.