Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expading list-items doesn't work with retrieve_async #1351

Closed
rafaelcapucho opened this issue Jun 24, 2024 · 2 comments
Closed

Expading list-items doesn't work with retrieve_async #1351

rafaelcapucho opened this issue Jun 24, 2024 · 2 comments
Assignees
Labels

Comments

@rafaelcapucho
Copy link

Describe the bug

Requesting list-items isn't working when using async requests

To Reproduce

  1. It's able to use retrieve_async(id) but it isn't supporting the expand option.
import stripe, asyncio

http_client = stripe.AIOHTTPClient()

client = stripe.StripeClient("rk_test_51ItkJ1F0XZ..redacted", http_client=http_client)

cs_id = "cs_test_a1Ew12lsEH1c..redacted"

async def function_working():
    return await client.checkout.sessions.retrieve_async(cs_id)

async def function_not_working():
    # None of the following works
    return await client.checkout.sessions.retrieve_async(cs_id, expand=['line_items'])
    return await client.checkout.sessions.retrieve_async(cs_id, params=['line_items'])
    return await client.checkout.sessions.retrieve_async(cs_id, params={'expand': 'line_items'})

loop = asyncio.new_event_loop()
loop.run_until_complete(function_working())

loop = asyncio.new_event_loop()
loop.run_until_complete(function_not_working())

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<stdin>", line 2, in f2
  File "/usr/local/lib/python3.12/site-packages/stripe/checkout/_session_service.py", line 2378, in retrieve_async
    await self._request_async(
  File "/usr/local/lib/python3.12/site-packages/stripe/_stripe_service.py", line 52, in _request_async
    return await self._requestor.request_async(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/stripe/_api_requestor.py", line 217, in request_async
    rbody, rcode, rheaders = await requestor.request_raw_async(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/stripe/_api_requestor.py", line 683, 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 434, 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 549, in _request_with_retries_internal_as                 ync
    raise connection_error
  File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 514, in _request_with_retries_internal_as                 ync
    response = await self.request_async(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1443, in request_async
    ) = await self.request_stream_async(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1474, in request_stream_async
    self._handle_request_error(e)
  File "/usr/local/lib/python3.12/site-packages/stripe/_http_client.py", line 1458, in _handle_request_error
    raise APIConnectionError(msg, should_retry=should_retry)
stripe._error.APIConnectionError: Unexpected error communicating with Stripe. If this problem persists,
let us know at support@stripe.com.

(Network error: A RuntimeError was raised)

Expected behavior

The session content with the items expanded.

Code snippets

No response

OS

Linux CoreOS

Language version

Python 3.12

Library version

Latest

API version

2024-04-10

Additional context

No response

@remi-stripe remi-stripe self-assigned this Jun 24, 2024
@remi-stripe
Copy link
Contributor

@rafaelcapucho none of the option you're using are correct which is why it's failing. What you need is this:

checkout_session = client.checkout.sessions.retrieve(
  'cs_test_123',
  params={
    'expand': ['line_items'],
  },
)

@rafaelcapucho
Copy link
Author

Thank you so much for the reply @remi-stripe,
Changing your snippet to retireve_async works, I'm closing the Issue

async def f3():
    print(
        await client.checkout.sessions.retrieve_async(
            cs_id,
            params={
                'expand': ['line_items'],
            },
        )
    )

loop = asyncio.new_event_loop()
loop.run_until_complete(f3())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants