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

标签 python stripe-payments attributeerror

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

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

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

最佳答案

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

解决方法如下:

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

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

关于 python Stripe : 'module' object has no attribute 'Charge' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20830784/

相关文章:

python - 如何在不使用await的情况下拆分长协程?

Python pandas合并2个相同大小的数据框

javascript - 带 Stripe 的柏树 : elements height not loaded

__del__ 上的 Python attributeError

Python - 域名的正则表达式

ios - 创建 Stripe 客户 ID 时出现 Alamofire 错误 (iOS)

python - Theano 中的名称冲突

python - 涉及 "AttributeError: ' 的奇怪错误 NoneType' 对象没有属性 'append' "

python - 用最合适的 "blocks"填充一个区域