Guest User

Untitled

a guest
Jan 8th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. url_to_check = 'http://clientdownload.xyz.com/Documents/abc.zip'
  2. username = "user"
  3. password = "pwd"
  4. p = urllib2.HTTPPasswordMgrWithDefaultRealm()
  5. p.add_password(None, url_to_check, username, password)
  6. handler = urllib2.HTTPBasicAuthHandler(p)
  7. opener = urllib2.build_opener(handler)
  8. urllib2.install_opener(opener)
  9. zip_file = urllib2.urlopen(url_to_check).read()
  10. file_name = 'somefile.zip'
  11. meta = zip_file.info()
  12. file_size = int(meta.getheaders("Content-Length")[0])
  13. print "Downloading: %s Bytes: %s" % (file_name, file_size)
  14.  
  15. with open(file_name, 'wb') as dwn_file:
  16. dwn_file.write(zip_file.read())
  17.  
  18. import urllib2, re, time, sys
  19.  
  20. theurl='http://clientdownload.xxx.com/Documents/Forms/AllItems.aspx'
  21.  
  22. req = urllib2.Request(theurl)
  23.  
  24. try:
  25. handle = urllib2.urlopen(req)
  26.  
  27. except IOError, e:
  28.  
  29. if hasattr(e, 'code'):
  30.  
  31. if e.code != 401:
  32. print 'We got another error'
  33. print e.code
  34. else:
  35. print e.headers
  36. print e.headers['www-authenticate']
  37.  
  38. Content-Type: text/html; charset=utf-8
  39. Server: Microsoft-IIS/7.5
  40. SPRequestGuid: 939bad00-40b7-49b9-bbbc-99d0267a1004
  41. X-SharePointHealthScore: 0
  42. WWW-Authenticate: NTLM
  43. X-Powered-By: ASP.NET
  44. MicrosoftSharePointTeamServices: 14.0.0.6029
  45. Date: Wed, 12 Feb 2014 13:14:19 GMT
  46. Connection: close
  47. Content-Length: 16
  48.  
  49. import requests
  50. from requests_ntlm import HttpNtlmAuth
  51.  
  52. r = requests.get("http://ntlm_protected_site.com",auth=HttpNtlmAuth('domain\username','password'))
Add Comment
Please, Sign In to add comment