1

I tried to download picture from internet, but it's very long.

This is my code :

import requests
url = "https://www.google.org/assets/static/images/logo_googledotorg-171e7482e5523603fc0eed236dd772d8.svg"
response = requests.get(url, headers={'Connection': 'close'}, stream=True)
print(response.elapsed)
del response

I get 0:00:05.412302

5 sec for a picture, i think it's very long.

Do you know what I have to do to get it more quickly?

Many thank's

Wansonce
  • 81
  • 2
  • 5
  • There are many reasons why this might take longer than you see if you use your browser. One possible reason is that the server throttles the download based on the useragent being passed in your request. E.g. See this question https://stackoverflow.com/questions/27652543/how-to-use-python-requests-to-fake-a-browser-visit – Tom Dalton Sep 22 '17 at 14:27
  • I tried to change the headers... nothing has changed... `0:00:05.493296` – Wansonce Sep 22 '17 at 15:12

1 Answers1

1

Is this because you are downloading an image file and that takes your internet connection 5 seconds? Try a different image that is significantly smaller and see if performance improves. No code variation is going to improve internet connection.

  • I tried many images take on Google Image, on my browser is less than 1 sec... I also tried `stream=False` and use `requests.head`... – Wansonce Sep 22 '17 at 13:57