【问题标题】:Python Stripe: 'module' object has no attribute 'Charge'Python Stripe:“模块”对象没有属性“电荷”
【发布时间】:2014-01-16 19:43:26
【问题描述】:

我已经在我的 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'
)

【问题讨论】:

  • 你调用了你的脚本stripe.py;你认为 Python 现在在导入 stripe 时首先会发现什么?

标签: python stripe-payments attributeerror


【解决方案1】:

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

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

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

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

【讨论】:

  • 好的,现在一切都清楚了......它已经按预期工作了
猜你喜欢
  • 2013-12-14
  • 2015-03-09
  • 2013-07-05
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
  • 2017-07-20
  • 2011-10-25
  • 2017-09-02
相关资源
最近更新 更多