0

I want to use the requests library to perform a stream get.

My endpoint is a long-running process that dumps output in the form of plaintext lines like:

Done with operation 1
Done with operation 2
etc...

But this endpoint could run for 10-30 minutes and I would like to get feedback about its current state without having to wait the full 30 minutes. I looked into stream=True for requests, but either my python (<3.5) doesn't support it or my endpoint response format isn't formatted to allow for streaming.

Can anyone tell me if it's possible to do this with requests? I do not have support for the async keyword in my python version.

import requests

res = request.get(endpointUrl, stream=True)
# Code execution pauses here even with stream enabled
for line in res.iter_lines():
    print(line) -> Expected: Done with operation 1

  • 1
    can you use a newer version of Python? – ti7 Feb 07 '22 at 20:35
  • Does this answer your question? [How could I use requests in asyncio?](https://stackoverflow.com/questions/22190403/how-could-i-use-requests-in-asyncio) – ti7 Feb 07 '22 at 20:35
  • The linked question doesn't look relevant, it's talking about running two queries in parallel, which I don't need, I need streaming output, not threaded requests. Additionally requires another 3rd party lib. –  Feb 07 '22 at 21:48

0 Answers0