3

I was hoping to get some help and clarification on what exactly elapsed is returning when using the Python Requests library. I've been reviewing the documentation here:

http://docs.python-requests.org/en/master/api/

But I'm skeptical of the time for download just because of how greatly is differs from what I've been doing. Here is what my code currently looks like:

import time
import requests


start = time.time() # what I've been using

# This is my download request. stream=False is default, so the entire file
# should be stored in memory. This makes me think that elapsed should be accurate. 
download_response = requests.get(URL, headers=_headers)

end = time.time()
dltime_requests = download_response.elapsed.total_seconds()
dltime_time = end - start

When comparing these two values, dltime_requests and dltime_time, the values differ greatly. Which would be more accurate? I've been downloading the same file over and over and the times between the two variables are very different, often by 100's of ms or even more than a second.

I know time.time() can be inaccurate, so maybe there is another library I should be using?

Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
  • Thanks @kcorlidy. I read through that one briefly before, but spending more time reading through it again I think I understand. Elapsed only provides time 'measured between sending the request and finishing parsing the response headers, not until the full response has been transfered.' – Justin Yarrington Nov 13 '18 at 14:30

0 Answers0