Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import requests
  2. from requests.auth import HTTPBasicAuth
  3.  
  4. theurl= 'example.com/file.txt'
  5. username = 'username'
  6. password = 'password'
  7.  
  8. r=requests.get(theurl, auth=HTTPBasicAuth(username, password))
  9.  
  10. import urllib.request
  11. # Create an OpenerDirector with support for Basic HTTP Authentication...
  12. auth_handler = urllib.request.HTTPBasicAuthHandler()
  13. auth_handler.add_password(realm='PDQ Application',
  14. uri='example.com/file.txt',
  15. user='username',
  16. passwd='password')
  17. opener = urllib.request.build_opener(auth_handler)
  18. # ...and install it globally so it can be used with urlopen.
  19. urllib.request.install_opener(opener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement