From 22976b08f7f8f53f96993b82fe629c54db83c862 Mon Sep 17 00:00:00 2001 From: zacchua-stripe Date: Thu, 12 Nov 2026 10:12:33 -0800 Subject: [PATCH 1/2] Link v17 migration guide to the wiki (#1977) Point the major changefile's migration guide link at the published wiki page and rebuild CHANGELOG.md. The previous link pointed at a branch or repo path that can move or be deleted. Committed-By-Agent: claude Co-authored-by: Claude Opus 5.5 --- .../changes/2026-10-30_zacchua_omit-pickled-api-keys.change.md | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.hark/changes/2026-10-30_zacchua_omit-pickled-api-keys.change.md b/.hark/changes/2026-10-30_zacchua_omit-pickled-api-keys.change.md index 3642fa3ee..bc7173ee9 100644 --- a/.hark/changes/2026-10-30_zacchua_omit-pickled-api-keys.change.md +++ b/.hark/changes/2026-10-30_zacchua_omit-pickled-api-keys.change.md @@ -6,4 +6,4 @@ released_in_version: 17.0.0 StripeObject pickles no longer preserve API keys. Before making requests through an unpickled object, call `reattach_api_key(api_key)`. This also reattaches API keys to nested objects. -See the [v17 migration guide](https://github.com/stripe/stripe-python/blob/master/.hark/migration-guides/v17.md#api-keys-are-no-longer-preserved-in-pickled-stripeobjects) for details. +See the [v17 migration guide](https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v17#api-keys-are-no-longer-preserved-in-pickled-stripeobjects) for details. diff --git a/CHANGELOG.md b/CHANGELOG.md index 168094b29..2f1f0bb35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Instead, edit a corresponding `.change.md` file and run `hark build`. StripeObject pickles no longer preserve API keys. Before making requests through an unpickled object, call `reattach_api_key(api_key)`. This also reattaches API keys to nested objects. - See the [v17 migration guide](https://github.com/stripe/stripe-python/blob/master/.hark/migration-guides/v17.md#api-keys-are-no-longer-preserved-in-pickled-stripeobjects) for details. + See the [v17 migration guide](https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v17#api-keys-are-no-longer-preserved-in-pickled-stripeobjects) for details. * Fix stale Stripe-Account header when fetching an object related to a directly-retrieved Event * Reject header values containing CR, LF or NUL in the pycurl HTTP client From 7254286570dcacb689f933db913e7cdf303818db Mon Sep 17 00:00:00 2001 From: itsrayeedscodespace Date: Fri, 13 Nov 2026 11:42:09 -0500 Subject: [PATCH 2/2] Allow configurable timeouts for PycurlClient (#1975) * fix: make PycurlClient timeouts configurable PycurlClient hardcoded CONNECTTIMEOUT=30 and TIMEOUT=80 on every request, unlike RequestsClient, HTTPXClient and AIOHTTPClient, which accept a `timeout` constructor argument. Add keyword-only `timeout` and `connect_timeout` arguments (defaults 80 and 30) after the existing parameters so positional callers are unaffected. Fixes #1962 * Remove unnecessary PycurlClient constructor docstring --- ...ace_pycurl-configurable-timeouts.change.md | 8 ++ stripe/_http_client.py | 9 +- tests/test_http_client.py | 101 ++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 .hark/changes/2026-11-06_itsrayeedscodespace_pycurl-configurable-timeouts.change.md diff --git a/.hark/changes/2026-11-06_itsrayeedscodespace_pycurl-configurable-timeouts.change.md b/.hark/changes/2026-11-06_itsrayeedscodespace_pycurl-configurable-timeouts.change.md new file mode 100644 index 000000000..0e93637c7 --- /dev/null +++ b/.hark/changes/2026-11-06_itsrayeedscodespace_pycurl-configurable-timeouts.change.md @@ -0,0 +1,8 @@ +--- +title: Add configurable `timeout` and `connect_timeout` to `PycurlClient` +semver_level: minor +github_issues_resolved: +- https://github.com/stripe/stripe-python/issues/1962 +--- + +`PycurlClient` now accepts keyword-only `timeout` (total request time, curl's `TIMEOUT`) and `connect_timeout` (curl's `CONNECTTIMEOUT`) arguments, in whole seconds. They default to the previous hardcoded values of 80 and 30 seconds. diff --git a/stripe/_http_client.py b/stripe/_http_client.py index 51740e156..f11f6c600 100644 --- a/stripe/_http_client.py +++ b/stripe/_http_client.py @@ -858,12 +858,17 @@ def __init__( proxy: Optional[HTTPClient._Proxy] = None, async_fallback_client: Optional[HTTPClient] = None, _lib=None, # used for internal unit testing + *, + timeout: int = 80, + connect_timeout: int = 30, ): super(PycurlClient, self).__init__( verify_ssl_certs=verify_ssl_certs, proxy=proxy, async_fallback_client=async_fallback_client, ) + self._timeout = timeout + self._connect_timeout = connect_timeout if _lib is None: import pycurl # pyright: ignore[reportMissingModuleSource] @@ -985,8 +990,8 @@ def _request_internal( curl.setopt(self.pycurl.WRITEFUNCTION, b.write) curl.setopt(self.pycurl.HEADERFUNCTION, rheaders.write) curl.setopt(self.pycurl.NOSIGNAL, 1) - curl.setopt(self.pycurl.CONNECTTIMEOUT, 30) - curl.setopt(self.pycurl.TIMEOUT, 80) + curl.setopt(self.pycurl.CONNECTTIMEOUT, self._connect_timeout) + curl.setopt(self.pycurl.TIMEOUT, self._timeout) _assert_no_header_injection(headers) curl.setopt( self.pycurl.HTTPHEADER, diff --git a/tests/test_http_client.py b/tests/test_http_client.py index 937eec3fa..153704ed8 100644 --- a/tests/test_http_client.py +++ b/tests/test_http_client.py @@ -1167,6 +1167,107 @@ def test_request_rejects_header_injection( with pytest.raises(ValueError): make_request("get", self.valid_url, headers, None) + @pytest.mark.parametrize( + "client_kwargs,expected_connect_timeout,expected_timeout", + [ + ({}, 30, 80), + ({"connect_timeout": 5, "timeout": 10}, 5, 10), + ({"connect_timeout": 5}, 5, 80), + ({"timeout": 10}, 30, 10), + ], + ) + def test_timeout( + self, + mocked_request_lib, + mock_response, + make_request, + client_kwargs, + expected_connect_timeout, + expected_timeout, + ): + mock_response(mocked_request_lib, '{"foo": "baz"}', 200) + make_request( + "GET", self.valid_url, {}, None, client_kwargs=client_kwargs + ) + + curl_mock = mocked_request_lib.Curl() + curl_mock.setopt.assert_any_call( + mocked_request_lib.CONNECTTIMEOUT, expected_connect_timeout + ) + curl_mock.setopt.assert_any_call( + mocked_request_lib.TIMEOUT, expected_timeout + ) + + def test_timeout_stream( + self, mocked_request_lib, mock_response, make_streamed_request + ): + mock_response(mocked_request_lib, "some streamed content", 200) + make_streamed_request( + "GET", + self.valid_url, + {}, + None, + client_kwargs={"connect_timeout": 5, "timeout": 10}, + ) + + curl_mock = mocked_request_lib.Curl() + curl_mock.setopt.assert_any_call(mocked_request_lib.CONNECTTIMEOUT, 5) + curl_mock.setopt.assert_any_call(mocked_request_lib.TIMEOUT, 10) + + def test_timeout_reapplied_after_reset( + self, mocked_request_lib, mock_response, make_client + ): + mock_response(mocked_request_lib, '{"foo": "baz"}', 200) + client = make_client(connect_timeout=5, timeout=10) + + client.request("get", self.valid_url, {}) + client.request("get", self.valid_url, {}) + + curl_mock = mocked_request_lib.Curl() + # reset() clears every option, so each request must set the + # timeouts again after its own reset() call. + relevant_calls = [ + c + for c in curl_mock.mock_calls + if c == call.reset() + or ( + c[0] == "setopt" + and c[1][0] + in ( + mocked_request_lib.CONNECTTIMEOUT, + mocked_request_lib.TIMEOUT, + ) + ) + ] + assert ( + relevant_calls + == [ + call.reset(), + call.setopt(mocked_request_lib.CONNECTTIMEOUT, 5), + call.setopt(mocked_request_lib.TIMEOUT, 10), + ] + * 2 + ) + + def test_positional_args(self, mocked_request_lib): + client = self.REQUEST_CLIENT(False, None, None, mocked_request_lib) + + assert client.pycurl is mocked_request_lib + assert client._verify_ssl_certs is False + assert client._connect_timeout == 30 + assert client._timeout == 80 + + # Timeouts are keyword-only so they can't be confused with each + # other or with the existing positional parameters. + with pytest.raises(TypeError): + self.REQUEST_CLIENT( + False, + None, + None, + mocked_request_lib, + 10, # pyright: ignore[reportGeneralTypeIssues] + ) + @pytest.fixture def created_curls(self, mocked_request_lib): curls: List[Mock] = []