Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- url_to_check = 'http://clientdownload.xyz.com/Documents/abc.zip'
- username = "user"
- password = "pwd"
- p = urllib2.HTTPPasswordMgrWithDefaultRealm()
- p.add_password(None, url_to_check, username, password)
- handler = urllib2.HTTPBasicAuthHandler(p)
- opener = urllib2.build_opener(handler)
- urllib2.install_opener(opener)
- zip_file = urllib2.urlopen(url_to_check).read()
- file_name = 'somefile.zip'
- meta = zip_file.info()
- file_size = int(meta.getheaders("Content-Length")[0])
- print "Downloading: %s Bytes: %s" % (file_name, file_size)
- with open(file_name, 'wb') as dwn_file:
- dwn_file.write(zip_file.read())
- import urllib2, re, time, sys
- theurl='http://clientdownload.xxx.com/Documents/Forms/AllItems.aspx'
- req = urllib2.Request(theurl)
- try:
- handle = urllib2.urlopen(req)
- except IOError, e:
- if hasattr(e, 'code'):
- if e.code != 401:
- print 'We got another error'
- print e.code
- else:
- print e.headers
- print e.headers['www-authenticate']
- Content-Type: text/html; charset=utf-8
- Server: Microsoft-IIS/7.5
- SPRequestGuid: 939bad00-40b7-49b9-bbbc-99d0267a1004
- X-SharePointHealthScore: 0
- WWW-Authenticate: NTLM
- X-Powered-By: ASP.NET
- MicrosoftSharePointTeamServices: 14.0.0.6029
- Date: Wed, 12 Feb 2014 13:14:19 GMT
- Connection: close
- Content-Length: 16
- import requests
- from requests_ntlm import HttpNtlmAuth
- r = requests.get("http://ntlm_protected_site.com",auth=HttpNtlmAuth('domain\username','password'))
Add Comment
Please, Sign In to add comment