Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from requests.auth import HTTPBasicAuth
- theurl= 'example.com/file.txt'
- username = 'username'
- password = 'password'
- r=requests.get(theurl, auth=HTTPBasicAuth(username, password))
- import urllib.request
- # Create an OpenerDirector with support for Basic HTTP Authentication...
- auth_handler = urllib.request.HTTPBasicAuthHandler()
- auth_handler.add_password(realm='PDQ Application',
- uri='example.com/file.txt',
- user='username',
- passwd='password')
- opener = urllib.request.build_opener(auth_handler)
- # ...and install it globally so it can be used with urlopen.
- urllib.request.install_opener(opener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement