#moonman239

1 messages · Page 1 of 1 (latest)

wide idolBOT
weak basin
#

Hi, taking a look.

vestal torrent
#

Thanks, Toby!

weak basin
#

Can you share what this line prints?
print(event.data.object)

vestal torrent
#

Just for reference, here's what my version of the Stripe API docs says:

"Retrieve an event:

In each case, the data dictionary will have an attribute called object and its value will be the same as retrieving the same object directly from the API. For example, a customer.created event will have the same information as retrieving the relevant customer would."

"The subscription object:

Attributes:

-items
list
List of subscription items, each with an attached price.

-- items.data
array of hashes
Details about each object."

There should be a price object under "items.data"

vestal torrent
#

I'm having trouble copying & pasting the whole thing into Discord chat

#

I'll save it to a txt file and then upload that

weak basin
#

Thank you, additionally, can you explain how your code is breaking? Is an error being encountered?

vestal torrent
#

Error: Traceback (most recent call last): File "C:\Python310\lib\site-packages\flask\app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "C:\Python310\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Python310\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "C:\Python310\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request rv = self.dispatch_request() File "C:\Python310\lib\site-packages\flask\app.py", line 1796, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "C:\Users\moonman239\Documents\xxx\app.py", line 166, in webhook subscription_product_id = subscription.items.data[0].price.product AttributeError: 'builtin_function_or_method' object has no attribute 'data'

#

Ah! It seems Python is just kindly letting me know that this is the correct syntax:

#

subscription_produjct_id = subscription["items"]["data"][0]["price"]["product"]

weak basin
#

Ah! So does pointing to product that way do what you were hoping it would?

vestal torrent
#

let me look

#

seems it does

#

weird that event.data.object works but everything else is a dictionary.

#

I mean, it's weird that "event" is an object with a "data" attribute, and "data" is an object with an "object" attribute, but "object" is a dictionary

#

for consistency, everything the Stripe library returns should be an object IMO.

weak basin
#

I don't think you'll see that style of typing for our libraries for non-strongly-typed languages.

#

That's good feedback though, thank you for that.