0

can anyone please tell me why i am not able to get the range of contents using content-range header,instead i am getting the whole content in given url.

import  requests
url="https://tools.ietf.org/rfc/rfc2822.txt "
content = requests.get(url)
content_len = int(content.headers['Content-Length'])
print(content_len)
headers = {f"Content-Range": f"bytes=0-100/{content_len}"}
r = requests.get(url, headers=headers)
print(r.content)
P Sairam
  • 1
  • 3

1 Answers1

1

Usually you would use Range and not Content-Range for requesting a subset of a resource. The server will then respond with a HTTP 206 (Partial Content) status and serve you with the requested range. The response will then contain a Content-Range as a header.

The following works for example:

import  requests

url = "https://tools.ietf.org/html/rfc7233"
headers = {"Range": "bytes=0-500"}
r = requests.get(url, headers=headers)
Alexander Kvist
  • 559
  • 6
  • 12