def requests_session(self): if self._requests_session is None: # We force pool size to 1 to ensure that only one # connection to the data collector which will be # maintained due to keep alive and reused. config = {} config['keep_alive'] = True config['pool_connections'] = 1 config['pool_maxsize'] = 1 self._requests_session = requests.session(config=config) return self._requests_session
def requests_session(self): if self._requests_session is None: # We force pool size to 1 to ensure that only one # connection to the data collector which will be # maintained due to keep alive and reused. config = {} config["keep_alive"] = True config["pool_connections"] = 1 config["pool_maxsize"] = 1 cert_loc = certifi.where() self._requests_session = requests.session(config=config, verify=cert_loc) return self._requests_session
def requests_session(self): if self._requests_session is None: # We force pool size to 1 to ensure that only one # connection to the data collector which will be # maintained due to keep alive and reused. config = {} config['keep_alive'] = True config['pool_connections'] = 1 config['pool_maxsize'] = 1 cert_loc = certifi.where() self._requests_session = requests.session(config=config, verify=cert_loc) return self._requests_session
data = zlib.compress(data, level) # The 'requests' library can raise a number of exception derived # from 'RequestException' before we even manage to get a connection # to the data collector. The data collector can the generate a # number of different types of HTTP errors for requests. try: session_config = {} session_config["keep_alive"] = True session_config["pool_connections"] = 1 session_config["pool_maxsize"] = 1 cert_loc = certifi.where() session = requests.session(config=session_config, verify=cert_loc) r = session.post(url, headers=headers, proxies=proxies, timeout=_collector_timeout, data=data) # Read the content now so we can force close the socket # connection if this is a transient session as quickly # as possible. content = r.content except requests.RequestException, exc: if not _proxy_host or not _proxy_port: _logger.warning( "Data collector is not contactable. This can be " "because of a network issue or because of the data " "collector being restarted. In the event that contact "
with InternalTrace('Supportability/Collector/ZLIB/Compress/' '%s' % method): data = zlib.compress(data, level) # If no requests session object for socket connection create one # now. We use a session object rather than direct post as want to # ensure that socket connection isn't kept alive by requests. if not session: session_config = {} session_config['keep_alive'] = True session_config['pool_connections'] = 1 session_config['pool_maxsize'] = 1 session = requests.session(config=session_config) # Send the request. We set 'verify' to be false so that when using # SSL there is no attempt to do SSL certificate validation. If it # were enabled then we would also need the 'certifi' library. # # The 'requests' library can raise a number of exception derived # from 'RequestException' before we even manage to get a connection # to the data collector. # # The data collector can the generate a number of different types of # HTTP errors for requests. These are: # # 400 Bad Request - For incorrect method type or incorrectly # construct parameters. We should not get this and if we do it would # likely indicate a problem with the implementation of the agent.
# designed flaws in the requests/urllib3 modules. See notes for # close_requests_session() function above. Note that keep alive # must be set to true at this point to ensure that the pool is # actually used to allow us to be able to close the connection. auto_close_session = False if not session: session_config = {} session_config['keep_alive'] = True session_config['pool_connections'] = 1 session_config['pool_maxsize'] = 1 cert_loc = certifi.where() session = requests.session(config=session_config, verify=cert_loc) auto_close_session = True # Send the request. We set 'verify' to be false so that when using # SSL there is no attempt to do SSL certificate validation. If it # were enabled then we would also need the 'certifi' library. # # The 'requests' library can raise a number of exception derived # from 'RequestException' before we even manage to get a connection # to the data collector. # # The data collector can the generate a number of different types of # HTTP errors for requests. These are: # # 400 Bad Request - For incorrect method type or incorrectly