@@ -480,26 +480,12 @@ checks can be relaxed by setting *ssl* to ``False``::
480
480
481
481
r = await session.get('https://example.com', ssl=False)
482
482
483
-
484
483
If you need to setup custom ssl parameters (use own certification
485
484
files for example) you can create a :class: `ssl.SSLContext ` instance and
486
- pass it into the proper :class: `ClientSession ` method::
487
-
488
- sslcontext = ssl.create_default_context(
489
- cafile='/path/to/ca-bundle.crt')
490
- r = await session.get('https://example.com', ssl=sslcontext)
491
-
492
- If you need to verify *self-signed * certificates, you can do the
493
- same thing as the previous example, but add another call to
494
- :meth: `ssl.SSLContext.load_cert_chain ` with the key pair::
485
+ pass it into the :meth: `ClientSession.request ` methods or set it for the
486
+ entire session with ``ClientSession(connector=TCPConnector(ssl=ssl_context)) ``.
495
487
496
- sslcontext = ssl.create_default_context(
497
- cafile='/path/to/ca-bundle.crt')
498
- sslcontext.load_cert_chain('/path/to/client/public/device.pem',
499
- '/path/to/client/private/device.key')
500
- r = await session.get('https://example.com', ssl=sslcontext)
501
-
502
- There is explicit errors when ssl verification fails
488
+ There are explicit errors when ssl verification fails
503
489
504
490
:class: `aiohttp.ClientConnectorSSLError `::
505
491
@@ -529,6 +515,34 @@ If you need to skip both ssl related errors
529
515
except aiohttp.ClientSSLError as e:
530
516
assert isinstance(e, ssl.CertificateError)
531
517
518
+ Example: Use certifi
519
+ ^^^^^^^^^^^^^^^^^^^^
520
+
521
+ By default, Python uses the system CA certificates. In rare cases, these may not be
522
+ installed or Python is unable to find them, resulting in a error like
523
+ `ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate `
524
+
525
+ One way to work around this problem is to use the `certifi ` package::
526
+
527
+ ssl_context = ssl.create_default_context(cafile=certifi.where())
528
+ async with ClientSession(connector=TCPConnector(ssl=ssl_context)) as sess:
529
+ ...
530
+
531
+ Example: Use self-signed certificate
532
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
533
+
534
+ If you need to verify *self-signed * certificates, you need to add a call to
535
+ :meth: `ssl.SSLContext.load_cert_chain ` with the key pair::
536
+
537
+ ssl_context = ssl.create_default_context()
538
+ ssl_context.load_cert_chain("/path/to/client/public/device.pem",
539
+ "/path/to/client/private/device.key")
540
+ async with sess.get("https://example.com", ssl=ssl_context) as resp:
541
+ ...
542
+
543
+ Example: Verify certificate fingerprint
544
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
545
+
532
546
You may also verify certificates via *SHA256 * fingerprint::
533
547
534
548
# Attempt to connect to https://www.python.org
0 commit comments