-
Notifications
You must be signed in to change notification settings - Fork 470
Closed
Labels
Description
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.
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