简体   繁体   English

'NoneType' object 没有属性 'get':AttributeError

[英]'NoneType' object has no attribute 'get': AttributeError

I am getting error: 'NoneType' object has no attribute 'get': AttributeError.我收到错误:“NoneType”object 没有属性“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)文件“/var/task/lambda_function.py”,第 15 行,在 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. event.get()可能是为检索事件中的数据而进行的错误调用类型。 As a result of this, the datatype would be collected and saved as NoneType .因此,数据类型将被收集并保存为NoneType

Referencing here , you can retrieve event items by calling event['item'] and not event.get('item').参考这里,您可以通过调用 event['item'] 而不是 event.get('item') 来检索事件项。

Here is an example:这是一个例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flasgger AttributeError:'NoneType'对象没有属性'get'吗? - Flasgger AttributeError: 'NoneType' object has no attribute 'get'? AttributeError: 'NoneType' object 没有属性 'get' helpp - AttributeError: 'NoneType' object has no attribute 'get' helpp AttributeError: 'NoneType' 对象没有属性 - AttributeError: 'NoneType' object has no attribute AttributeError:“ NoneType”对象没有属性“ a” - AttributeError: 'NoneType' object has no attribute 'a' AttributeError: 'NoneType' object 没有属性 'get' - get.("href") - AttributeError: 'NoneType' object has no attribute 'get' - get.("href") 如何处理AttributeError:'NoneType'对象在大字典中没有属性'get' - How to handle AttributeError: 'NoneType' object has no attribute 'get' in big dictionary Kivy AttributeError: 'NoneType' 对象没有属性 'get_screen' - Kivy AttributeError: 'NoneType' object has no attribute 'get_screen' AttributeError:当我保存在age中时,“ NoneType”对象没有属性“ get” - AttributeError: 'NoneType' object has no attribute 'get' when I save in amage AttributeError:“ NoneType”对象在循环时没有属性“ get” - AttributeError: 'NoneType' object has no attribute 'get' while on loop Python-AttributeError:“ NoneType”对象没有属性“ get_text” - Python - AttributeError: 'NoneType' object has no attribute 'get_text'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM