⚡ Solution Summary

  • Upgrade to stripe-python version 14.4.1 to resolve SSL certificate verification issues.
  • The issue was identified in version 11.4.0.
  • The fix is confirmed by the maintainers.
### Describe the bug With version 11.4.0 I am getting `httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)`. If I downgrade to 11.3.0 the error goes away. This seems to only happen when running under asyncio. ### To Reproduce ```bash pip install stripe==11.3.0 python <<'EOF' import asyncio import stripe import stripe.checkout def main(): stripe.default_http_client = stripe.HTTPXClient() stripe.api_key = "YOUR_API_KEY" price_id = "YOUR_PRICE_ID" asyncio.run( stripe.checkout.Session.create_async( customer_email="test@test.com", ui_mode="embedded", line_items=[ { "price": price_id, "quantity": 1, }, ], mode="subscription", return_url=f"http://localhost:3000/payment-complete?session_id={{CHECKOUT_SESSION_ID}}", ) ) main() EOF # >> No error pip install stripe==11.4.0 python <<'EOF' import asyncio import stripe import stripe.checkout def main(): stripe.default_http_client = stripe.HTTPXClient() stripe.api_key = "YOUR_API_KEY" price_id = "YOUR_PRICE_ID" asyncio.run( stripe.checkout.Session.create_async( customer_email="test@test.com", ui_mode="embedded", line_items=[ { "price": price_id, "quantity": 1, }, ], mode="subscription", return_url=f"http://localhost:3000/payment-complete?session_id={{CHECKOUT_SESSION_ID}}", ) ) main() EOF # >> see error ``` ### Expected behavior I expect there to be no error using version 11.4.0 of the library. ### Code snippets See above ### OS macOS and Fedora ### Language version Python 3.9.15 and Python 3.12.2 ### Library version stripe-python==11.4.0 ### API version 2024-12-18.acacia ### Additional context Full stack trace: ``` Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions yield File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 394, in handle_async_request resp = await self._pool.handle_async_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request raise exc from None File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request response = await connection.handle_async_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request raise exc File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 78, in handle_async_request stream = await self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_async/connection.py", line 156, in _connect stream = await stream.start_tls(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 67, in start_tls with map_exceptions(exc_map): File "/usr/lib64/python3.12/contextlib.py", line 158, in __exit__ self.gen.throw(value) File "/usr/local/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1313, in request_async response = await self._client_async.request(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1540, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1629, in send response = await self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1657, in _send_handling_auth response = await self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects response = await self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1730, in _send_single_request response = await transport.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 393, in handle_async_request with map_httpcore_exceptions(): File "/usr/lib64/python3.12/contextlib.py", line 158, in __exit__ self.gen.throw(value) File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>", line 27, in <module> File "<stdin>", line 11, in main File "/usr/lib64/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/asyncio/base_events.py", line 685, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/checkout/_session.py", line 4491, in create_async await cls._static_request_async( File "/usr/local/lib/python3.12/site-packages/stripe/_api_resource.py", line 190, in _static_request_async return await _APIRequestor._global_instance().request_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/_api_requestor.py", line 220, in request_async rbody, rcode, rheaders = await requestor.request_raw_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/_api_requestor.py", line 803, in request_raw_async ) = await self._get_http_client().request_with_retries_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 439, in request_with_retries_async return await self._request_with_retries_internal_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 554, in _request_with_retries_internal_async raise connection_error File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 519, in _request_with_retries_internal_async response = await self.request_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1315, in request_async self._handle_request_error(e) File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1331, in _handle_request_error raise APIConnectionError(msg, should_retry=should_retry) from e stripe._error.APIConnectionError: Unexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com. (Network error: A ConnectError was raised) ```

Discussion & Fixes

sileht 2024-12-19
This seems related to this commit: https://github.com/stripe/stripe-python/commit/12637de43efa1af5e4a2cd5948c94ac9b5ec11e7
jar-stripe 2024-12-19
Hi @e-carlin thanks for the report, and thanks for the initial investigation @sileht ! Sorry for the inconvenience here; we're working on a fix now and will rerelease the SDK once its merged.
xavdid-stripe 2024-12-19
We've released version `14.4.1` to address this issue. Sorry about the hassle!
e-carlin 2024-12-20
All good. Thanks for the quick turnaround!

Prevent idempotency bugs?

SolvedStack indexes fixes, but OnceOnly prevents duplicate processing and race conditions by design.

Try OnceOnly