Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!usr/bin/env python3
- import os
- import sys
- import base64
- import urllib.request
- import shutil
- def checkEnv(name, strict=False):
- if not name in os.environ or os.environ[name] == '':
- if strict:
- print('Error need env var \'%s\'' % (name))
- sys.exit(22)
- return False
- return os.environ[name]
- def download(url, dest, headers):
- req = urllib.request.Request(url)
- for header in headers:
- req.add_header(header, headers[header])
- with urllib.request.urlopen(req) as response, \
- open(dest, 'wb') as out_file:
- shutil.copyfileobj(response, out_file)
- def main():
- username = 'AUTH_USER'
- username = checkEnv(username, strict=True)
- password = 'AUTH_PASS'
- password = checkEnv(password, strict=True)
- url = 'URL'
- url = checkEnv(url, strict=True)
- dest = 'DEST'
- dest = checkEnv(dest, strict=True)
- concat = username + ":" + password
- concat = concat.encode('utf8')
- download(url, dest, {
- 'Autorization': 'Basic %s' % (base64.b64encode(concat))
- })
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement