简体   繁体   中英

Python Stripe: 'module' object has no attribute 'Charge'

I have installed Stripe on my MacOSX Mavericks Macbook Pro (python 2.7) using

but I always get the following error message:

$ sudo python stripe.py
Traceback (most recent call last):
  File "stripe.py", line 1, in <module>
    import stripe
  File "/Users/sebastian/Desktop/stripe.py", line 7, in <module>
    resp = stripe.Charge.create(
AttributeError: 'module' object has no attribute 'Charge'

when I try to execute the following script:

import stripe

stripe.api_key = 'my_test_secret_key'

resp = stripe.Charge.create(
    amount=200,
    currency='usd',
    card={
        'number': '4242424242424242',
        'exp_month': 10,
        'exp_year': 2014
    },
    description='customer@gmail.com'
)

You have another file that is called stripe.py , so this file is getting imported instead of the stripe library.

Here's how you fix this:

  • Rename your stripe.py file to something different
  • Remove stripe.pyc if it exists (mind the c )

Said file is on your desktop: /Users/sebastian/Desktop/stripe.py .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM