8000 Use ssl_context for HTTPS requests to avoid reading certificate files… · polygon-io/client-python@7cb5208 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cb5208

Browse files
Use ssl_context for HTTPS requests to avoid reading certificate files on every request (#632)
* Use ssl_context for HTTPS requests to avoid reading certificate files on every request * Update base.py Added comment to explain logic --------- Co-authored-by: justinpolygon <123573436+justinpolygon@users.noreply.github.com>
1 parent 0b5fa9b commit 7cb5208

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

polygon/rest/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import certifi
22
import json
3+
import ssl
34
import urllib3
45
import inspect
56
from urllib3.util.retry import Retry
@@ -66,13 +67,16 @@ def __init__(
6667
backoff_factor=0.1, # [0.0s, 0.2s, 0.4s, 0.8s, 1.6s, ...]
6768
)
6869

70+
# global cache ssl context and use (vs on each init of pool manager)
71+
ssl_context = ssl.create_default_context()
72+
ssl_context.load_verify_locations(certifi.where())
73+
6974
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html
7075
# https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool
7176
self.client = urllib3.PoolManager(
7277
num_pools=num_pools,
7378
headers=self.headers, # default headers sent with each request.
74-
ca_certs=certifi.where(),
75-
cert_reqs="CERT_REQUIRED",
79+
ssl_context=ssl_context,
7680
retries=retry_strategy, # use the customized Retry instance
7781
)
7882

0 commit comments

Comments
 (0)
0