I am trying to download a binary file smaller than 1 MB through urequests with basic authentication. The authentication part works and I get the expected response.
But the truth is I feel lost since I can't download the file I need and I have to do it through urequests.
Can you give me a hand?
website = 'www.example.com/api'
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')}
r = urequests.get(website, headers=headers)
Edit:
Due to the "limitations" of the urequests library, I have tried this one: mrequests
Best library: https://github.com/SpotlightKid/mrequests
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.bin",1024)
r.close()
I ended up editing the Save method to handle the download percentage of the required file. It is not mandatory, but a progress bar is always healthy ;-)