I think that curlthey headwill work better than the Python solution:
curl https://my.website.com/file.txt | head -c 512 > header.txt
EDIT: , Python script, subprocess curl head
EDIT 2: Python: urlopen (urllib2.urlopen Python 2 urllib.request.urlopen Python 3) , , read . , urllib2.urlopen(my_url).read(512) 512 my_url