⚡ Solution Summary

  • Upgrade to stripe-python v11 when available for a fix.
  • Currently, use json_body to bypass the issue.
  • Bug report acknowledged and fix is in progress.
### Describe the bug We have noticed a strange bug that when upgrading from v7 -> v8. StripeError -> http_body becomes None instead of valid dictionary ### To Reproduce Fill STRIPE_GB_SECRET_KEY with valid test/dev key and run the script. You will see that `http_body` is None, while `json_body` is valid dict. This is starting from v8. Before v8 both http_body and json_body contain identical data. ```python import stripe import os from dotenv import load_dotenv import shortuuid import json # Load environment variables from .env file load_dotenv() # Configure Stripe with your test API key stripe.api_key = os.getenv('STRIPE_GB_SECRET_KEY') def test_stripe_charge(): # Test parameters metadata = {} metadata['moto_charge'] = False params = { "amount": 2000, # $20.00 in cents "currency": "USD", "customer": "cus_xxx", # Replace with a test customer ID "description": "Test charge from script", "idempotency_key": shortuuid.uuid(), "metadata": metadata } try: print("Attempting to create charge...") stripe_charge = stripe.Charge.create(**params) print("Charge successful!") print(f"Charge ID: {stripe_charge.id}") print(f"Amount: ${stripe_charge.amount/100}") print(f"Status: {stripe_charge.status}") return stripe_charge except stripe.error.InvalidRequestError as e: # Invalid parameters were supplied to Stripe's API print(f"Invalid Request Error: {str(e)}") print(f"Invalid Request Error: {str(e.http_body)}") print(f"Invalid Request Error: {str(e.json_body)}") print(json.dumps(e.json_body, indent=2)) if __name__ == "__main__": test_stripe_charge() ``` ### Expected behavior Suddenly http_body instead of giving dict starts giving None. I think this is backward compatibility issue. ### Code snippets _No response_ ### OS macOS ### Language version 3.8 ### Library version stripe-python v8.0.0 ### API version Not sure ### Additional context _No response_

Discussion & Fixes

jar-stripe 2024-12-16
Hi @eduard-grigoryan-ext-bark, thank you for reporting this! I think I see the issue, and I've added this to the backlog to get fixed in an upcoming SDK release. Is this issue preventing you from upgrading your SDK version, and could you upgrade to the latest version (v11) if it were fixed in that version?
eduard-grigoryan-ext-bark 2024-12-17
> Hi @eduard-grigoryan-ext-bark, thank you for reporting this! I think I see the issue, and I've added this to the backlog to get fixed in an upcoming SDK release. Is this issue preventing you from upgrading your SDK version, and could you upgrade to the latest version (v11) if it were fixed in that version? We have already switched on using json_body to bypass the problem. I reported bug for the future and for other developers.
jar-stripe 2024-12-17
@eduard-grigoryan-ext-bark Thanks for confirming, and appreciate the bug report! Glad you were able to work around the issue here. An update on the bug itself: the fix has been merged into the master branch, and will go out with the next release. Thanks again!

Prevent idempotency bugs?

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

Try OnceOnly