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


Python aiohttp.BasicAuth方法代码示例

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


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

示例1: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def __init__(self, cfg_file, callback, loop=None, username=None, password=None):
        """
        cfg_file: dictionary or filename or yaml text
        """
        self.config = StreamConfigReader().read(cfg_file)
        self.callback = callback
        self._loop = loop or asyncio.get_event_loop()
        self._queue = asyncio.Queue(maxsize=20, loop=self._loop)

        auth = None
        if username != None and password != None:
            auth = aiohttp.BasicAuth(login=username, password=password, encoding='utf-8')

        self.session = aiohttp.ClientSession(
                read_timeout=self.config.timeout,
                conn_timeout=self.config.timeout,
                raise_for_status=True,
                loop=self._loop,
                auth=auth) 
开发者ID:madedotcom,项目名称:atomicpuppy,代码行数:21,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def __init__(self, api, host, port, username, password,
                 iter_cnt=-1, iter_delay=600,
                 task_timeout=120, worker_cnt=4,
                 post_timeout=60, no_verify_ssl=False):
        '''[summary]
        '''
        self._api = api
        self._workers = []
        self._iter_cnt = iter_cnt
        self._iter_delay = iter_delay
        self._worker_cnt = worker_cnt
        self._task_queue = Queue()
        self._task_timeout = task_timeout
        self._output_lock = Lock()
        self._url = f'https://{host}:{port}/mkctf-api/healthcheck'
        self._ssl = False if no_verify_ssl else None
        self._auth = BasicAuth(username, password)
        self._post_timeout = ClientTimeout(total=post_timeout) 
开发者ID:koromodako,项目名称:mkctf,代码行数:20,代码来源:monitor.py

示例3: push

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def push(self, host, port=443, tags=[], categories=[],
                   username='', password='', no_verify_ssl=False):
        '''Push challenge configuration to a scoreboard
        '''
        self.__assert_valid_repo()
        challenges = []
        for challenge in self._repo.scan(tags, categories):
                challenges.append(challenge.conf.raw)
        url = f'https://{host}:{port}/mkctf-api/push'
        ssl = False if no_verify_ssl else None
        auth = BasicAuth(username, password)
        timeout = ClientTimeout(total=2*60)
        async with ClientSession(auth=auth, timeout=timeout) as session:
            async with session.post(url, ssl=ssl, json={'challenges': challenges}) as resp:
                if resp.status < 400:
                    app_log.info("push succeeded.")
                    return {'pushed': True}
        app_log.error("push failed.")
        return {'pushed': False} 
开发者ID:koromodako,项目名称:mkctf,代码行数:21,代码来源:api.py

示例4: create_session

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def create_session(self, loop):
        conn = None

        if self.proxy and self.proxy_user:
            conn = aiohttp.ProxyConnector(
                loop=loop,
                limit=self.parallel,
                proxy=self.proxy,
                proxy_auth=aiohttp.BasicAuth(self.proxy_user, self.proxy_password)
            )
        elif self.proxy:
            conn = aiohttp.ProxyConnector(loop=loop, limit=self.parallel, proxy=self.proxy)
        else:
            conn = aiohttp.TCPConnector(loop=loop, limit=self.parallel)

        session = aiohttp.ClientSession(connector=conn)
        return session 
开发者ID:icoxfog417,项目名称:mlimages,代码行数:19,代码来源:__init__.py

示例5: update_proxy

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def update_proxy(self, proxy, proxy_auth, proxy_headers):
        if proxy and proxy.scheme not in ['http', 'socks4', 'socks5']:
            raise ValueError(
                "Only http, socks4 and socks5 proxies are supported")
        if proxy and proxy_auth:
            if proxy.scheme == 'http' and \
                    not isinstance(proxy_auth, aiohttp.BasicAuth):
                raise ValueError("proxy_auth must be None or "
                                 "BasicAuth() tuple for http proxy")
            if proxy.scheme == 'socks4' and \
                    not isinstance(proxy_auth, Socks4Auth):
                raise ValueError("proxy_auth must be None or Socks4Auth() "
                                 "tuple for socks4 proxy")
            if proxy.scheme == 'socks5' and \
                    not isinstance(proxy_auth, Socks5Auth):
                raise ValueError("proxy_auth must be None or Socks5Auth() "
                                 "tuple for socks5 proxy")
        self.proxy = proxy
        self.proxy_auth = proxy_auth
        self.proxy_headers = proxy_headers 
开发者ID:nibrag,项目名称:aiosocks,代码行数:22,代码来源:connector.py

示例6: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def __init__(
        self,
        *,
        url: Union[str, URL] = BASE,
        use_user_agent: bool = False,
        forwarded_for: Optional[str] = None,
        proxy: Optional[str] = None,
        proxy_auth: Optional[aiohttp.BasicAuth] = None,
        timeout: Union[float, int] = 150,
        max_requests: int = 250,
        debug: bool = False,
        **kwargs,
    ) -> None:
        self.semaphore = asyncio.Semaphore(max_requests)
        self.url = URL(url)
        self.use_agent = use_user_agent
        self.forwarded_for = forwarded_for
        self.proxy = proxy
        self.proxy_auth = proxy_auth
        self.timeout = timeout
        self.debug = debug
        self.last_result = None  # for testing 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:24,代码来源:http_request.py

示例7: async_update

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def async_update(self):
    try:
      auth = aiohttp.BasicAuth(self.username, self.password)
      with async_timeout.timeout(TIMEOUT, loop=self.hass.loop):
        response = await self.websession.get(ENDPOINT, auth=auth)
        data = await response.json(content_type=None)
        if len(data) > 0:
          _LOGGER.debug("Updating sensor: {}".format(data))
          entry = data[0]
          self._meal = entry['meal']
          self.extract_deilver_date(entry['deliveryDate'])
        else:
          _LOGGER.debug("No data to update: {}".format(data))
          self._deliver_from = None
          self._deliver_to = None
          self._time_left = None
          self._meal = None
    except (asyncio.TimeoutError, aiohttp.ClientError, IndexError) as error:
      _LOGGER.error("Failed getting devices: %s", error) 
开发者ID:macbury,项目名称:SmartHouse,代码行数:21,代码来源:sensor.py

示例8: get_request

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def get_request(self, uri, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.get(
                        uri,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                        timeout=60,
                    ) as _response:
                        await _response.read()
        except (Exception, TimeoutError) as ex:
            if _continue:
                return
            else:
                self.logger.debug(ex)
                self.logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
开发者ID:redhat-performance,项目名称:badfish,代码行数:21,代码来源:badfish.py

示例9: post_request

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def post_request(self, uri, payload, headers):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.post(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        if _response.status != 204:
                            await _response.read()
                        else:
                            return _response
        except (Exception, TimeoutError):
            self.logger.exception("Failed to communicate with server.")
            raise BadfishException
        return _response 
开发者ID:redhat-performance,项目名称:badfish,代码行数:21,代码来源:badfish.py

示例10: patch_request

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def patch_request(self, uri, payload, headers, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.patch(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        await _response.read()
        except Exception as ex:
            if _continue:
                return
            else:
                self.logger.debug(ex)
                self.logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
开发者ID:redhat-performance,项目名称:badfish,代码行数:22,代码来源:badfish.py

示例11: get

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def get(self, endpoint):
        logger.debug("GET: %s" % endpoint)
        try:
            async with aiohttp.ClientSession(
                loop=self.loop
            ) as session:
                async with session.get(
                    self.url + endpoint,
                    auth=BasicAuth(self.username, self.password),
                    verify_ssl=False,
                ) as response:
                    result = await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return {}
        return result 
开发者ID:redhat-performance,项目名称:quads,代码行数:19,代码来源:foreman.py

示例12: put_host_parameter

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def put_host_parameter(self, host_id, parameter_id, value):
        logger.debug("PUT param: {%s:%s}" % (parameter_id, value))
        endpoint = "/hosts/%s/parameters/%s" % (host_id, parameter_id)
        data = {'parameter': {"value": value}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.put(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 204]:
            logger.info("Host parameter updated successfully.")
            return True
        return False 
开发者ID:redhat-performance,项目名称:quads,代码行数:26,代码来源:foreman.py

示例13: post_host_parameter

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def post_host_parameter(self, host_id, name, value):
        logger.debug("PUT param: {%s:%s}" % (name, value))
        endpoint = "/hosts/%s/parameters" % host_id
        data = {"parameter": {"name": name, "value": value}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.post(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 201, 204]:
            logger.info("Host parameter updated successfully.")
            return True
        return False 
开发者ID:redhat-performance,项目名称:quads,代码行数:26,代码来源:foreman.py

示例14: update_user_password

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def update_user_password(self, login, password):
        logger.debug("PUT login pass: {%s}" % login)
        _host_id = await self.get_user_id(login)
        endpoint = "/users/%s" % _host_id
        data = {"user": {"login": login, "password": password}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.put(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 204]:
            logger.info("User password updated successfully.")
            return True
        return False 
开发者ID:redhat-performance,项目名称:quads,代码行数:27,代码来源:foreman.py

示例15: get_request

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import BasicAuth [as 别名]
def get_request(self, uri, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(loop=self.loop) as session:
                    async with session.get(
                        uri,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                        timeout=60,
                    ) as _response:
                        await _response.text("utf-8", "ignore")
        except (Exception, TimeoutError) as ex:
            if _continue:
                return
            else:
                logger.debug(ex)
                logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
开发者ID:redhat-performance,项目名称:quads,代码行数:21,代码来源:badfish.py


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