Python Stripe:'module'对象没有属性'Charge'

时间:2013-12-29 22:25:30

标签: python stripe-payments attributeerror

我使用

在我的MacOSX Mavericks Macbook Pro(python 2.7)上安装了 Stripe

但我总是收到以下错误消息:

$ 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'

当我尝试执行以下脚本时:

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'
)

1 个答案:

答案 0 :(得分:6)

您有另一个名为stripe.py的文件,因此导入此文件而不是stripe库。

以下是解决此问题的方法:

  • 将您的stripe.py文件重命名为不同的文件
  • 删除stripe.pyc(如果它存在(请注意c

所述文件位于您的桌面上:/Users/sebastian/Desktop/stripe.py