python - file size differences - requests module vs chrome -
i really puzzled issue i'm running into. have script downloading image files off of imgur. script leverages requests module. in essence, request made open link byte stream, , file downloaded chunks , placed in in-memory buffer. here simple version of do:
page_binary_string = io.bytesio response = requests.get(url, stream=true) chunk in response.iter_content(chunk_size, decode_unicode): page_binary_string.write(chunk)
in case, decode_unicode going set false. write resulting stream file using
image_file = open(path, 'wb') # open file updating image_file.write(page_binary_string.read(page_binary_string.size))
when @ resultant file in file system, 1/20 of size of file browser downloaded!!!
here link experimenting @ moment: http://i.imgur.com/vbauzys.jpg
if download file browser, can see 244kb. when @ file on disk, 10kb. size difference obvious when opening image. quality has drastically deteriorated.
anyone have ideas why happening , how fix it? http header (encodings??) first guess, i'm not sold on this.
if there no specific reason why use io.bytestream can use requests module's own raw content functionality. take here http://docs.python-requests.org/en/latest/user/quickstart/#binary-response-content can either way, or open file in binary mode (open('somefile.jpg', 'wb')) , dump contents in there quick , dirty stuff.
Comments
Post a Comment