简体   繁体   中英

'NoneType' object has no attribute 'get': AttributeError

I am getting error: 'NoneType' object has no attribute 'get': AttributeError. PLease help me to figure out.

File "/var/task/lambda_function.py", line 15, in lambda_handler create_stripe_customer(cardData,phone,email)

import json
import boto3
import stripe
client = boto3.client('secretsmanager')
keys = json.loads(client.get_secret_value(
  SecretId = 'arn:aws:secretsmanager:ap-so',
)['SecretString'])
public_key = keys['stripe-public']
secret_key = keys['stripe-secret']
stripe.api_key = secret_key
def lambda_handler(event, context):
    cardData = event.get('cardData')
    phone = event.get('phone')
    email = event.get('email')
    create_stripe_customer(cardData,phone,email)
    return event

def create_stripe_customer(payment_info, phone, email):
    customer_id = stripe.Customer.create( phone = phone,email=email)['id']
    payment_method_id = create_payment_method(payment_info)
    stripe.PaymentMethod.attach(payment_method_id, customer = customer_id)
    return {"customer_id": customer_id,
            "plan": create_stripe_plan(customer_id)
    }

def create_payment_method(payment_info):
    return stripe.PaymentMethod.create(type = "card",
    card = {"number": payment_info.get('cardNumber'),
            "exp_month": payment_info.get('expirationMonth'),
            "exp_year": payment_info.get('expirationYear'),
            "cvc": payment_info.get('ccv'),
            }).get('id')      
        
def create_stripe_plan(customer_id):
    return stripe.Subscription.create(
        customer = customer_id,items = [{"plan": "plan_idxxxxxxx"}]).get("id")

Why it doesn't work


event.get() may be the wrong type of call to be making to retrieve the data within event. As a result of this, the datatype would be collected and saved as NoneType .

Referencing here , you can retrieve event items by calling event['item'] and not event.get('item').

Here is an example:

def my_handler(event, context):
    message = 'Hello {} {}!'.format(event['first_name'], 
                                    event['last_name'])  
    return { 
        'message' : message
    }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM