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


Python aiohttp.ClientTimeout方法代码示例

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


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

示例1: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [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

示例2: push

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [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

示例3: run

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def run(self, host):
        tasks = []
        # 默认limit=100,enable_cleanup_closed设置为True防止ssl泄露,ttl_dns_cache调高dns缓存
        conn = aiohttp.TCPConnector(
            limit=LIMIT,
            enable_cleanup_closed=True,
            ttl_dns_cache=100,
            ssl=False,
        )
        timeout = aiohttp.ClientTimeout(total=60, connect=2)
        async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
            for url in self.urls:
                task = asyncio.ensure_future(self.scan(host, url, session))
                tasks.append(task)
            # gather方法是所有请求完成后才有输出
            _ = await asyncio.gather(*tasks)
            # for i in asyncio.as_completed(tasks):  # 类似于线程池中的task一样
            #     answer = await i
    
    # 创建启动任务 
开发者ID:al0ne,项目名称:Vxscan,代码行数:22,代码来源:async_scan.py

示例4: _get_response

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def _get_response(self, full_url, headers, timeout):
        try:
            timeout = aiohttp.ClientTimeout(total=self.TIMEOUT_SECONDS)
            async with self._session(timeout=timeout) as session:
                async with session.get(full_url, headers=headers) as resp:
                    if resp.status != 200:
                        text = await resp.text()
                        raise MetadataRetrievalError(
                            error_msg=(
                                          "Received non 200 response (%d) "
                                          "from ECS metadata: %s"
                                      ) % (resp.status, text))
                    try:
                        return await resp.json()
                    except ValueError:
                        text = await resp.text()
                        error_msg = (
                            "Unable to parse JSON returned from ECS metadata services"
                        )
                        logger.debug('%s:%s', error_msg, text)
                        raise MetadataRetrievalError(error_msg=error_msg)
        except RETRYABLE_HTTP_ERRORS as e:
            error_msg = ("Received error when attempting to retrieve "
                         "ECS metadata: %s" % e)
            raise MetadataRetrievalError(error_msg=error_msg) 
开发者ID:aio-libs,项目名称:aiobotocore,代码行数:27,代码来源:utils.py

示例5: test_connect_proxy_ip

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_connect_proxy_ip(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        loop.getaddrinfo = make_mocked_coro(
             [[0, 0, 0, 0, ['127.0.0.1', 1080]]])

        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://proxy.org'))
        connector = ProxyConnector(loop=loop)
        conn = await connector.connect(req, [], ClientTimeout())

    assert loop.getaddrinfo.called
    assert conn.protocol is proto

    conn.close() 
开发者ID:nibrag,项目名称:aiosocks,代码行数:20,代码来源:test_connector.py

示例6: test_connect_proxy_domain

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_connect_proxy_domain():
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        loop_mock = mock.Mock()

        req = ProxyClientRequest(
            'GET', URL('http://python.org'),  loop=loop_mock,
            proxy=URL('socks5://proxy.example'))
        connector = ProxyConnector(loop=loop_mock)

        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 1
    assert conn.protocol is proto

    conn.close() 
开发者ID:nibrag,项目名称:aiosocks,代码行数:21,代码来源:test_connector.py

示例7: test_connect_remote_resolve

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_connect_remote_resolve(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://127.0.0.1'))
        connector = ProxyConnector(loop=loop, remote_resolve=True)
        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 1
    assert conn.protocol is proto

    conn.close() 
开发者ID:nibrag,项目名称:aiosocks,代码行数:18,代码来源:test_connector.py

示例8: test_connect_locale_resolve

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_connect_locale_resolve(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://proxy.example'))
        connector = ProxyConnector(loop=loop, remote_resolve=False)
        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 2
    assert conn.protocol is proto

    conn.close() 
开发者ID:nibrag,项目名称:aiosocks,代码行数:18,代码来源:test_connector.py

示例9: test_proxy_connect_http

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_proxy_connect_http(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')
    loop_mock = mock.Mock()
    loop_mock.getaddrinfo = make_mocked_coro([
        [0, 0, 0, 0, ['127.0.0.1', 1080]]])
    loop_mock.create_connection = make_mocked_coro((tr, proto))
    loop_mock.create_task.return_value = asyncio.Task(
        make_mocked_coro([
            {'host': 'host', 'port': 80, 'family': 1,
             'hostname': 'hostname', 'flags': 11, 'proto': 'proto'}])())

    req = ProxyClientRequest(
        'GET', URL('http://python.org'), loop=loop,
        proxy=URL('http://127.0.0.1'))
    connector = ProxyConnector(loop=loop_mock)

    await connector.connect(req, [], ClientTimeout()) 
开发者ID:nibrag,项目名称:aiosocks,代码行数:19,代码来源:test_connector.py

示例10: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def __init__(self):
        super().__init__()

        self.setLayout(QVBoxLayout())

        self.lblStatus = QLabel('Idle', self)
        self.layout().addWidget(self.lblStatus)

        self.editUrl = QLineEdit(self._DEF_URL, self)
        self.layout().addWidget(self.editUrl)

        self.editResponse = QTextEdit('', self)
        self.layout().addWidget(self.editResponse)

        self.btnFetch = QPushButton('Fetch', self)
        self.btnFetch.clicked.connect(self.on_btnFetch_clicked)
        self.layout().addWidget(self.btnFetch)

        self.session = aiohttp.ClientSession(
            loop=asyncio.get_event_loop(),
            timeout=aiohttp.ClientTimeout(total=self._SESSION_TIMEOUT)) 
开发者ID:gmarull,项目名称:asyncqt,代码行数:23,代码来源:aiohttp_fetch.py

示例11: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def __init__(self, ports=[80], extended=False):
        RobotAdapter.__init__(self, ports, extended)
        self.rosin_nodes = ['/streaming_client',            # ABB
                            '/motion_download_interface',   # ABB
                            '/robot_state',                 # ABB
                            '/joint_trajectory_action',     # ABB
                            '/kuka_eki_hw_interface',       # KUKA
                            '/controller_spawner',          # KUKA
                            '/motion_streaming_interface',  # FANUC
                            '/industrial_robot_client',     # FANUC
                            '/joint_state',                 # FANUC
                            '/kuka_rsi_simulator'           # KUKA
                            ]
        self.timeout = aiohttp.ClientTimeout(total=3)
        self.logger = logging.getLogger(__name__)
        self.hosts = []
        self.rate = 1000 
开发者ID:aliasrobotics,项目名称:aztarna,代码行数:19,代码来源:scanner.py

示例12: subscribe

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def subscribe(self):
        # This connection should live ~forever, so disable some timeouts.
        timeout = aiohttp.ClientTimeout(
            total=None, sock_read=None, connect=30, sock_connect=30,
        )
        async with aiohttp.ClientSession(timeout=timeout) as session:
            payload = '{"type":"SUBSCRIBE"}'
            master_host_port = mesos_tools.find_mesos_leader(cluster=self.cluster)
            async with session.post(
                f"http://{master_host_port}/api/v1",
                data=payload,
                # allow_redirects=True,
                headers={"Content-Type": "application/json"},
                timeout=timeout,
            ) as resp:
                while True:
                    _size = await resp.content.readline()
                    if not _size:
                        break
                    size = int(_size)
                    record = await resp.content.readexactly(size)
                    yield json.loads(record) 
开发者ID:Yelp,项目名称:paasta,代码行数:24,代码来源:log_task_lifecycle_events.py

示例13: create_client_session

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def create_client_session(*args, **kwargs) -> aiohttp.ClientSession:
    """
    Creates client session with resonable defaults.
    For details about available parameters refer to
    `aiohttp.ClientSession <https://docs.aiohttp.org/en/stable/client_reference.html>`_

    Examplary customization:

    .. code-block:: python

        from galaxy.http import create_client_session, create_tcp_connector

        session = create_client_session(
            headers={
                "Keep-Alive": "true"
            },
            connector=create_tcp_connector(limit=40),
            timeout=100)
    """
    kwargs.setdefault("connector", create_tcp_connector())
    kwargs.setdefault("timeout", aiohttp.ClientTimeout(total=DEFAULT_TIMEOUT))
    kwargs.setdefault("raise_for_status", True)
    # due to https://github.com/python/mypy/issues/4001
    return aiohttp.ClientSession(*args, **kwargs)  # type: ignore 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:26,代码来源:http.py

示例14: _start_detached

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def _start_detached(
        self, timeout: aiohttp.ClientTimeout = None, tty: bool = False,
    ) -> bytes:
        if self._tty is None:
            await self.inspect()  # should restore tty
        assert self._tty is not None
        async with self.docker._query(
            f"exec/{self._id}/start",
            method="POST",
            headers={"Content-Type": "application/json"},
            data=json.dumps({"Detach": True, "Tty": tty}),
            timeout=timeout,
        ) as response:
            result = await response.read()
            await response.release()
            return result 
开发者ID:aio-libs,项目名称:aiodocker,代码行数:18,代码来源:execs.py

示例15: test_can_choose_a_different_timeout_on_client_instantiation

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import ClientTimeout [as 别名]
def test_can_choose_a_different_timeout_on_client_instantiation(self):
        new_timeout = ClientTimeout(total=2, connect=5)
        client = HttpClient(timeout=new_timeout)
        client.session_class = self.session_class_mock

        await client.get(TEST_URL)

        client.session_class.assert_called_with(
            timeout=new_timeout, headers=ANY, raise_for_status=True
        )

        client._session.request.assert_awaited_with(
            "get",
            ANY,
            timeout=None,
            headers=ANY,
            allow_redirects=True,
            raise_for_status=True,
        ) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:21,代码来源:test_http_client.py


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