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


Python requests.sessions方法代码示例

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


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

示例1: __init__

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def __init__(self, config):
        from .configuration import Configuration
        if not isinstance(config, Configuration):
            raise ValueError("'config' %r must be a Configuration instance" % config)
        if not config.service_endpoint:
            raise AttributeError("'config.service_endpoint' must be set")
        self.config = config
        self._session_pool_size = self.SESSION_POOLSIZE

        # Autodetect authentication type if necessary
        if self.config.auth_type is None:
            self.config.auth_type = self.get_auth_type()

        # Try to behave nicely with the remote server. We want to keep the connection open between requests.
        # We also want to re-use sessions, to avoid the NTLM auth handshake on every request. We must know the
        # authentication method to create a session pool.
        self._session_pool = self._create_session_pool()
        self._session_pool_lock = Lock() 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:20,代码来源:protocol.py

示例2: close

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def close(self):
        log.debug('Server %s: Closing sessions', self.server)
        while True:
            try:
                self._session_pool.get(block=False).close()
            except Empty:
                break 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:9,代码来源:protocol.py

示例3: _create_session_pool

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def _create_session_pool(self):
        # Create a pool to reuse sessions containing connections to the server
        session_pool = LifoQueue()
        for _ in range(self._session_pool_size):
            session_pool.put(self.create_session(), block=False)
        return session_pool 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:8,代码来源:protocol.py

示例4: get_session

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def get_session(self):
        _timeout = 60  # Rate-limit messages about session starvation
        while True:
            try:
                log.debug('Server %s: Waiting for session', self.server)
                session = self._session_pool.get(timeout=_timeout)
                log.debug('Server %s: Got session %s', self.server, session.session_id)
                session.usage_count += 1
                return session
            except Empty:
                # This is normal when we have many worker threads starving for available sessions
                log.debug('Server %s: No sessions available for %s seconds', self.server, _timeout) 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:14,代码来源:protocol.py

示例5: release_session

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def release_session(self, session):
        # This should never fail, as we don't have more sessions than the queue contains
        log.debug('Server %s: Releasing session %s', self.server, session.session_id)
        if self.MAX_SESSION_USAGE_COUNT and session.usage_count > self.MAX_SESSION_USAGE_COUNT:
            log.debug('Server %s: session %s usage exceeded limit. Discarding', self.server, session.session_id)
            session = self.renew_session(session)
        try:
            self._session_pool.put(session, block=False)
        except Full:
            log.debug('Server %s: Session pool was already full %s', self.server, session.session_id) 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:12,代码来源:protocol.py

示例6: clear_cache

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def clear_cache(mcs):
        for key, protocol in mcs._protocol_cache.items():
            if isinstance(protocol, Exception):
                continue
            service_endpoint = key[0]
            log.debug("Service endpoint '%s': Closing sessions", service_endpoint)
            protocol.close()
        mcs._protocol_cache.clear() 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:10,代码来源:protocol.py

示例7: __init__

# 需要导入模块: import requests [as 别名]
# 或者: from requests import sessions [as 别名]
def __init__(self):
        self.session = requests.sessions.Session() 
开发者ID:rinodung,项目名称:udemy-dl-windows,代码行数:4,代码来源:udemy-dl.py


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