Is there any way to download files from web by chunks? In normal python, you can use
Code: Select all
requests.get(url, stream=True)
Code: Select all
requests.get(url, stream=True)
Code: Select all
>>> import mrequests
>>> r = mrequests.get('http://httpbin.org/image', headers={'accept': 'image/png'})
>>> r.save("image.png")
Code: Select all
>>>while True:
>>> chunk = r.read(chunksize)
>>> if not chunk:
>>> break
>>> process(chunk)
Code: Select all
>>> import mrequests
>>> r = mrequests.get('http://httpbin.org/image', headers={'accept': 'image/png'})
>>> r.save("image.png")
Code: Select all
>>> while True:
>>> chunk = r.read (chunksize)
>>> if not chunk:
>>> break
>>> process (chunk)
Currently I have been able to accomplish my purpose as follows:SpotlightKid wrote: ↑Wed Aug 11, 2021 6:12 pmPlease show the actual code that doesn't work (please link to code, or copy and paste it exactly here, no screenshots or incomplete code) and also copy & paste the exact error message, if any.
Code: Select all
import mrequests
username = 'test'
password = 'test'
auth_str = '%s:%s' % (username, password)
b64_auth_str = b2a_base64(auth_str)
headers = {'Authorization': 'Basic %s' % b64_auth_str.decode('utf-8'),'accept': 'multipart/form-data'}
url = "https://domainexample.com/file.bin"
r = mrequests.get(url, headers=headers)
r.save("file.csv",1024)
r.close()