1

I am trying to download only range of bytes of a file and I am trying the following process:

r = requests.get('https://stackoverflow.com', headers={'Range':'bytes=0-999'})

But it give status code 200 as opposed to 206 and I am getting the entire file.

I tried following this Python: How to download file using range of bytes? but it also gave me status code 200. What is the reason and how do I download files partially using python?

Headers for stackoverflow:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Last-Modified: Fri, 04 Aug 2017 05:28:29 GMT
X-Frame-Options: SAMEORIGIN
X-Request-Guid: 86fd186e-b5ac-472f-9d79-c45149343776  
Strict-Transport-Security: max-age=15552000
Content-Length: 107699
Accept-Ranges: bytes
Date: Wed, 06 Sep 2017 11:48:16 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-sin18023-SIN
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1504698496.659820,VS0,VE404
Vary: Fastly-SSL
X-DNS-Prefetch-Control: off
Set-Cookie: prov=6df82a45-2405-b1dd-1430-99e27827b360; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Cache-Control: private
Krash
  • 2,085
  • 3
  • 13
  • 36

1 Answers1

2

This requires server-side support. Probably the server does not support it.

To find out, make a HEAD request and see if the response has Accept-Ranges.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • In the header, I can see Accept-Ranges: bytes and according to https://tools.ietf.org/html/rfc2616#section-14.5 , it means partial downloading is supported – Krash Sep 06 '17 at 12:13
  • What's the actual URL you're using? – John Zwinck Sep 06 '17 at 12:15
  • @johnZwink, its stack overflow in his post. – LhasaDad Sep 06 '17 at 12:18
  • I am using stackoverflow.com. Does it work for you with stackoverflow.com ? – Krash Sep 06 '17 at 12:19
  • @Krash `HEAD https://stackoverflow.com` will get `Accept-Ranges` as `bytes`. However, when send range request, `200 OK` and the whole html file is returned. – shaochuancs Sep 06 '17 at 12:42
  • I suspect what's happening is the server supports range requests only for certain files (e.g. images), not for everything. – John Zwinck Sep 06 '17 at 12:44
  • @JohnZwinck I don't think that is the case. When I do a partial get to stackoverflow.com/ , if it wasn't possible to download it partially, this request's header wouldn't contain Accept-Ranges, but it did. – Krash Sep 06 '17 at 16:29