【问题标题】:Google App Engine + Flask + Stripe: Attribute Error: AttributeError: 'function' object has no attribute 'Customer'Google App Engine + Flask + Stripe:属性错误:AttributeError:'function'对象没有属性'Customer'
【发布时间】:2014-06-30 19:18:06
【问题描述】:

我正在使用 Google App Engine、Flask 和 Stripe 为我的蜜月创建一个迷你博客,我们可以将其发送给家人和朋友。一切都很好,除了 Stripe。

收到错误:

File "/Users/MDev/Desktop/Steph_Max/Wedding/main.py", line 131, in charge
customer = stripe.Customer.create(
AttributeError: 'function' object has no attribute 'Customer'

这是它在错误中引用的代码行。

@app.route('/stripe')
def stripe():

return render_template('stripe.html', key=stripe_keys['publishable_key'])

@app.route('/charge', methods=['POST'])
def charge():
  # Amount in cents
  amount = 500

  customer = stripe.Customer.create(
    email = 'customer@example.com',
    card = request.form['stripeToken']
  )

  charge = stripe.Charge.create(
    customer=customer.id,
    amount=amount,
    currency='usd',
    description='Flask Charge'
  )

  return render_template('charge.html', amount=amount)

我有我的main.py 设置,在 Stripe 文档中只有默认结帐为 documented

from flask import Flask
from flask import render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
from flask import send_from_directory
import stripe
import os


app = Flask(__name__)
#app.config['DEBUG'] = True

stripe_keys = {
    'secret_key' : os.environ['SECRET_KEY'],
    'publishable_key' : os.environ['PUBLISHABLE_KEY']
}



stripe.api_key = stripe_keys['secret_key']

我的index 页面可以正常工作(我已将其重命名为stripe.html),但问题在于它何时进入charge 页面。条纹按钮的脚本正在运行,我可以提交一张假卡,除了收费页面之外一切正常。

我是菜鸟的菜鸟,所以请耐心等待我,如果我遗漏了什么,我会尽快更新:)

版本:

  • 条纹:stripe-1.14.0-py2.7.egg-info
  • Python:2.7
  • GAE:1.9.3

【问题讨论】:

  • 请提供完整代码。包括文件顶部的导入
  • 已添加,感谢指点。

标签: google-app-engine python-2.7 flask stripe-payments


【解决方案1】:

问题是你已经导入了条带库,然后定义了一个同名的函数。

【讨论】:

  • 谢谢!我最惨! :D
猜你喜欢
  • 1970-01-01
  • 2020-10-26
  • 2019-09-06
  • 1970-01-01
  • 2011-08-16
  • 1970-01-01
  • 2016-03-10
  • 2022-01-26
  • 2019-05-17
相关资源
最近更新 更多