MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / create_session

Method create_session

dwave/cloud/client/base.py:589–627  ·  view source on GitHub ↗

Create a new requests session based on client's (self) params. Note: since `requests.Session` is NOT thread-safe, every thread should create and use an isolated session.

(self)

Source from the content-addressed store, hash-verified

587 pass
588
589 def create_session(self):
590 """Create a new requests session based on client's (self) params.
591
592 Note: since `requests.Session` is NOT thread-safe, every thread should
593 create and use an isolated session.
594 """
595
596 # allow endpoint path to not end with /
597 endpoint = self.config.endpoint
598 if not endpoint.endswith('/'):
599 endpoint += '/'
600
601 session = self._Session(base_url=endpoint, strict_mode=True,
602 on_deprecation=self._DEFAULT_ON_DEPRECATION_CONFIG)
603 session.mount('http://', PretimedHTTPAdapter(
604 timeout=self.config.request_timeout,
605 max_retries=self.config.request_retry.to_urllib3_retry()))
606 session.mount('https://', PretimedHTTPAdapter(
607 timeout=self.config.request_timeout,
608 max_retries=self.config.request_retry.to_urllib3_retry()))
609
610 session.headers.update({'User-Agent': default_user_agent()})
611 if self.config.headers:
612 session.headers.update(self.config.headers)
613 if self.config.token:
614 session.headers.update({'X-Auth-Token': self.config.token})
615 if self.config.cert:
616 session.cert = self.config.cert
617
618 session.proxies = {'http': self.config.proxy, 'https': self.config.proxy}
619 if self.config.permissive_ssl:
620 session.verify = False
621 if self.config.connection_close:
622 session.headers.update({'Connection': 'close'})
623
624 # Debug-log headers
625 logger.trace("create_session(session.headers=%r)", session.headers)
626
627 return session
628
629 def _shutdown_threads(self, wait: bool = True):
630 # Finish all the work that requires the connection

Calls 3

PretimedHTTPAdapterClass · 0.90
default_user_agentFunction · 0.90
to_urllib3_retryMethod · 0.80