Streaming API tends to keep the request open allowing us to collect the stream data in real time. While dealing with a continuous stream of data, to ensure that none of the messages being missed from it we can take the help of
iter_lines() in Requests. The
iter_lines() iterates over the response data line by line. This can be achieved by setting the parameter stream as
True while sending the request.
It's better to keep in mind that it's not always safe to call the
iter_lines() function as it may result in loss of received data.
Consider the following example taken from http://docs.python-requests.org/en/latest/user/advanced/#streaming-requests:
>>> import json >>> import requests >>> r = requests.get('http://httpbin.org/stream/4', ...