Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Beta: Fix HTTPXClient retries #1209

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion stripe/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,6 @@ async def request_async(
response = await self._client.request(
method, url, headers=headers, data=post_data or {}, **kwargs
)
response.raise_for_status()
except Exception as e:
self._handle_request_error(e)

Expand Down
29 changes: 28 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def do_request(self, n):
assert "A ReadTimeout was raised" in str(exception.user_message)

@pytest.mark.asyncio
async def test_async_raw_request_retries(self):
async def test_async_httpx_raw_request_retries(self):
class MockServerRequestHandler(MyTestHandler):
def do_request(self, n):
if n == 0:
Expand All @@ -365,3 +365,30 @@ def do_request(self, n):
req = reqs[0]

assert req.path == "/v1/customers"

@pytest.mark.asyncio
async def test_async_httpx_raw_request_unretryable(self):
class MockServerRequestHandler(MyTestHandler):
def do_request(self, n):
return (
401,
{"Request-Id": "req_1"},
b'{"error": {"message": "Unauthorized"}}',
)

pass

self.setup_mock_server(MockServerRequestHandler)
stripe.api_base = "http://localhost:%s" % self.mock_server_port

exception = None
try:
await stripe.raw_request_async(
"post", "/v1/customers", description="My test customer"
)
except stripe.AuthenticationError as e:
exception = e

MockServerRequestHandler.get_requests(1)
assert exception is not None
assert "Unauthorized" in str(exception.user_message)
Loading