Google App Engine + Flask + Stripe: Attribute Error: AttributeError: 'function' object has no attribute 'Customer'
Question: I'm starting a mini blog for my honeymoon with Google App Engine, Flask and
Stripe that we can send to family and friends. Everythings working great,
except for Stripe.

Error Received:

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

This is the code line it's referring to in the error.

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

I have my `main.py` setup with just the default checkout as
[documented](https://stripe.com/docs/checkout/guides/flask) in Stripe docs:

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

My `index` page works (I've renamed it `stripe.html`) but the issue is just
when it goes to the `charge` page. The script for the stripe button is
working, I can submit a fake card, everything works except unto the charge
page.

I'm on the noob side of noob so please be patient with me and if I'm missing
something I'll update ASAP :)

Versions:

  * stripe: stripe-1.14.0-py2.7.egg-info
  * Python: 2.7
  * GAE: 1.9.3


Answer: The problem is you have imported the stripe library and then defined a
function with the same name.

