make certifi import optional
this allows users to uninstall certifi if they have objections
to its MPL license.
@@ -35,7 +35,6 @@ import json
import re
import ssl
-import certifi
import urllib3
from urllib3.exceptions import MaxRetryError, TimeoutError
@@ -44,6 +43,11 @@ from elasticapm.transport.http_base import HTTPTransportBase
from elasticapm.utils import compat, json_encoder, read_pem_file
from elasticapm.utils.logging import get_logger
+try:
+ import certifi
+except ImportError:
+ certifi = None
+
logger = get_logger("elasticapm.transport.http")
@@ -51,7 +55,8 @@ class Transport(HTTPTransportBase):
def __init__(self, url, *args, **kwargs):
super(Transport, self).__init__(url, *args, **kwargs)
url_parts = compat.urlparse.urlparse(url)
- pool_kwargs = {"cert_reqs": "CERT_REQUIRED", "ca_certs": certifi.where(), "block": True}
+ ca_certs = certifi.where() if certifi else None
+ pool_kwargs = {"cert_reqs": "CERT_REQUIRED", "ca_certs": ca_certs, "block": True}
if self._server_cert and url_parts.scheme != "http":
pool_kwargs.update(
{"assert_fingerprint": self.cert_fingerprint, "assert_hostname": False, "cert_reqs": ssl.CERT_NONE}
