I am using the Python library requeststo send a POST request. The part of the program that produces the POST data can be written to an arbitrary file object (output stream).
How can I make these two parts suitable?
I would suggest that it requestsprovides a streaming interface for this use case, but it doesn't seem to do it. It takes as an argument a datafile-like object from which it reads . It does not provide a file-like object to which I can write .
Is this a fundamental problem with Python HTTP libraries?
Ideas so far:
It seems like the easiest solution is fork()to have the request library interact with the POST data producer, h strong>.
Is there a better way?
Alternatively, I could try to complicate the POST data producer. However, it is parsing a single XML stream (from stdin) and creating a new XML stream for use as POST data. Then I have the same problem in the reverse order: XML serializer libraries want to write to a file-like object, I don’t know about the possibility that the XML serializer provides a file-like object from which another can read .
, , - , Python (yield). POST (yield) pull-parser.
requests POST? XML, yield?
- -, - / - , ?