Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • pip install --index-url https://code.stripe.com --upgrade stripe
  • easy_install --index-url https://code.stripe.com --upgrade stripe
  • python setup.py install

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='[email protected]'
)
like image 515
Sebastian Auberger Avatar asked Feb 15 '23 06:02

Sebastian Auberger


1 Answers

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.

like image 138
Thomas Orozco Avatar answered Feb 17 '23 02:02

Thomas Orozco