Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python requests stream reads more data than chunk size

I am using python requests library to stream the data from a streaming API.

response = requests.get('http://server/stream-forever', stream=True)
for chunk in response.iter_content(chunk_size=1024):
    print len(chunk) # prints 1905, 1850, 1909

I have specified the chunk size as 1024. Printing the length of the chunk read gives the chunk size greater than 1024 like 1905, 1850, 1909 and so on.

Am I missing something here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

According to requests.Response.iter_content docs

(…)The chunk size is the number of bytes it should read into memory. This
is not necessarily the length of each item returned as decoding can
take place.(…)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading