Python-对象不可序列化
我是python新手,正在为我的项目编写API 我能够获取该对象,但是每当我尝试执行Python-对象不可序列化,python,json,Python,Json,我是python新手,正在为我的项目编写API 我能够获取该对象,但是每当我尝试执行json.dumps(sub_entry.\uu dict_uuu)时,就会出现错误订阅类型的对象不是json可序列化的 我怀疑这是因为这个“\u response\u obj':{'subscription': 上面的\u响应对象不在原始子条目中,仅在打印子条目后显示。 有人能帮我吗 分录: { "subscription": { "id": &q
json.dumps(sub_entry.\uu dict_uuu)
时,就会出现错误订阅类型的对象不是json可序列化的
我怀疑这是因为这个“\u response\u obj':{'subscription':
上面的\u响应对象
不在原始子条目
中,仅在打印子条目后显示。
有人能帮我吗
分录:
{
"subscription": {
"id": "16COUVSU397xz4Cg9",
"plan_id": "P04",
"plan_quantity": 1,
"plan_unit_price": 6800,
"billing_period": 1,
"billing_period_unit": "month",
"customer_id": "16COUVSU397xz4Cg9",
"plan_amount": 6800,
"plan_free_quantity": 0,
"status": "active",
"current_term_start": 1618325269,
"current_term_end": 1620917269,
"next_billing_at": 1620917269,
"created_at": 1617937215,
"started_at": 1617937215,
"activated_at": 1617937215,
"created_from_ip": "182.239.117.243",
"updated_at": 1618325278,
"has_scheduled_changes": false,
"resource_version": 1618325278117,
"deleted": false,
"object": "subscription",
"coupon": "TEST-FREE",
"currency_code": "HKD",
"coupons": [
{
"coupon_id": "TEST-FREE",
"applied_count": 2,
"object": "coupon"
}
],
"due_invoices_count": 0,
"mrr": 0,
"exchange_rate": 1.0,
"base_currency_code": "HKD"
},
"customer": {
"id": "16COUVSU397xz4Cg9",
"email": "liam.leung@binery.co",
"auto_collection": "on",
"net_term_days": 0,
"allow_direct_debit": false,
"created_at": 1617937215,
"created_from_ip": "182.239.117.243",
"taxability": "taxable",
"updated_at": 1618322530,
"pii_cleared": "active",
"resource_version": 1618322530322,
"deleted": false,
"object": "customer",
"billing_address": {
"first_name": "Liam",
"last_name": "Leung",
"line1": "Hk",
"city": "Hong Kong",
"country": "HK",
"validation_status": "not_validated",
"object": "billing_address"
},
"card_status": "valid",
"promotional_credits": 0,
"refundable_credits": 0,
"excess_payments": 0,
"unbilled_charges": 0,
"preferred_currency_code": "HKD",
"primary_payment_source_id": "pm_Azq8bBSU39g1k4CdR",
"payment_method": {
"object": "payment_method",
"type": "card",
"reference_id": "cus_JGhzp8fcSX2p6D/pm_1IeAZsEEy6BVvQ9BSRZPFda2",
"gateway": "stripe",
"gateway_account_id": "gw_16CKhcSQyHkLn5rW",
"status": "valid"
}
},
"card": {
"status": "valid",
"gateway": "stripe",
"gateway_account_id": "gw_16CKhcSQyHkLn5rW",
"iin": "******",
"last4": "7616",
"card_type": "mastercard",
"funding_type": "debit",
"expiry_month": 7,
"expiry_year": 2025,
"issuing_country": "HK",
"created_at": 1617937216,
"updated_at": 1617937216,
"ip_address": "182.239.117.243",
"powered_by": "not_applicable",
"resource_version": 1617937216831,
"object": "card",
"masked_number": "************7616",
"customer_id": "16COUVSU397xz4Cg9",
"payment_source_id": "pm_Azq8bBSU39g1k4CdR"
}
}
分录。分录:
{'_response': {'subscription': {'id': '21433j2fadsf', 'plan_id': 'P04', 'plan_quantity': 1, 'plan_unit_price': 6800, 'billing_period': 1, 'billing_period_unit': 'month', 'customer_id': '234fasdfe3fdsa', 'plan_amount': 6800, 'plan_free_quantity': 0, 'status': 'active', 'current_term_start': 1618325269, 'current_term_end': 1620917269, 'next_billing_at': 1620917269, 'created_at': 1617937215, 'started_at': 1617937215, 'activated_at': 1617937215, 'created_from_ip': '182.239.117.243', 'updated_at': 1618325278, 'has_scheduled_changes': False, 'resource_version': 1618325278117, 'deleted': False, 'object': 'subscription', 'coupon': 'TEST-FREE', 'currency_code': 'HKD', 'coupons': [{'coupon_id': 'TEST-FREE', 'applied_count': 2, 'object': 'coupon'}], 'due_invoices_count': 0, 'mrr': 0, 'exchange_rate': 1.0, 'base_currency_code': 'HKD'}, 'customer': {'id': '16COUVSU397xz4Cg9', 'email': 'email@email.co', 'auto_collection': 'on', 'net_term_days': 0, 'allow_direct_debit': False, 'created_at': 1617937215, 'created_from_ip': '182.239.117.243', 'taxability': 'taxable', 'updated_at': 1618322530, 'pii_cleared': 'active', 'resource_version': 1618322530322, 'deleted': False, 'object': 'customer', 'billing_address': {'first_name': 'Liam', 'last_name': 'Leung', 'line1': 'Hk', 'city': 'Hong Kong', 'country': 'HK', 'validation_status': 'not_validated', 'object': 'billing_address'}, 'card_status': 'valid', 'promotional_credits': 0, 'refundable_credits': 0, 'excess_payments': 0, 'unbilled_charges': 0, 'preferred_currency_code': 'HKD', 'primary_payment_source_id': 'pm_q34f32dd3', 'payment_method': {'object': 'payment_method', 'type': 'card', 'reference_id': 'cus_JAhzpfa3fD8fcSX2p6D/pm_1IeAZs5yfaGg5vQ9BSRZFda2', 'gateway': 'stripe', 'gateway_account_id': 'gw_16CKhcSQyHkLn5rW', 'status': 'valid'}}, 'card': {'status': 'valid', 'gateway': 'stripe', 'gateway_account_id': 'gw_16CKhcSQyHkLn5rW', 'iin': '******', 'last4': '7616', 'card_type': 'mastercard', 'funding_type': 'debit', 'expiry_month': 7, 'expiry_year': 2025, 'issuing_country': 'HK', 'created_at': 1617937216, 'updated_at': 1617937216, 'ip_address': '182.239.117.243', 'powered_by': 'not_applicable', 'resource_version': 1617937216831, 'object': 'card', 'masked_number': '************8777', 'customer_id': '16IUUV6ER77xz4Cg9', 'payment_source_id': 'pm_Azq8bBSU39g1k4CdR'}}, '_response_obj': {'subscription': <chargebee.models.subscription.Subscription object at 0x10307ceb8>}}
{u响应:{'subscription':{'id':'21433j2fadsf','plan_id':'P04','plan_quantity':1','plan_unit_price':6800','billing_period':1','billing_period_unit':'month','customer_id':'234fasdfe3fdsa','plan_amount':6800,'plan_free_quantity':0',status':'active','current_term_start':16183252;(term(end':1620917269,'1617937215,‘开始于’:1617937215,‘激活于’:1617937215,‘从ip创建’:‘182.239.117.243’,‘更新于’:1618325278,‘已安排变更’:False,‘资源版本’:1618325278117,‘删除’:False,‘对象’:‘订阅’,‘优惠券’:‘免测试’,‘货币代码’:‘港币’,‘优惠券’:[{'优惠券id':'TEST-FREE','applied_count':2,'object':'Council'}],'due_invoices_count':0,'mrr':0,'exchange_rate':1.0,'base_currency_code':'HKD','customer':{'id':'16COUVSU397xz4Cg9','email':'email@email.co“,”自动托收“:”on“,”net_term_days“:0,“允许直接借记”:False“,”created_at“:1617937215“,”created_from_ip“:”182.239.117.243“,”taxiability“:”应纳税“,”updated_at“,”1618322530“,”pii_cleared“:”active“,”资源版本“,”161832250322“,”已删除“,”False“,”对象“:”客户“,”账单”ing_地址:{'first_name':'Liam','last_name':'Leung','line1':'Hk','city':'Hong','country':'Hk','validation_status':'not_validated','object':'billing_address'},“卡状态”:“有效”,“促销积分”:0,“可退款积分”:0,“超额付款”:0,“未开票费用”:0,“首选货币代码”:“港币”,“主要付款来源id”:“下午q34f32dd3”,“付款方式”:{'object':'payment_method','type':'card','reference_id':'cus_JAhzpfa3fD8fcSX2p6D/pm_1eazs5yfag5vq9bsrzfda2','gateway':'stripe','gateway__帐户_id':'gw_16CKhcSQyHkLn5rW','status':'valid'},'card':{'status':'valid','gateway':'stripe','gateway_account_id':'gw_16CKhcSQyHkLn5rW','iin':'****','last4':'7616','card_type':'mastercard','funding_type':'debit','expiration_月':7,'expiration年:'2025,'发行国':'HK','created_at:'1617937216','updated(更新的(at:'1617937216','ip地址:'182.239.117.243;','b.'le,“资源版本”:1617937216831,“对象”:“卡”,“屏蔽号码”:“*******************8777”,“客户id”:“16IUUV6ER77xz4Cg9”,“付款来源id”:“pm_Azq8bBSU39g1k4CdR”},“响应对象”:“{“订阅”:}”
您需要将chargebee.models.subscription.subscription对象转换为json/dict/str格式first@sahasrara62该chargebee.models.subscription.subscription
对象在sub\u条目
中未显示,它仅在执行sub\u条目后显示。我不确定在此可以执行哪些操作这将有助于我建议您不要使用obj.\uu dict\uuuuuu
从表模型中获取数据(考虑到这是来自orm的表数据),您可以使用{c.name:getattr(self,c.name)来表示self中的c.\uu table\uuuuuuuu.columns}/code>来获取json格式的所有表数据。我已经通过执行以下操作解决了这个问题:json.dumps(sub_entry,default=lambda x:getattr(x,'.''.'dict'.'str(x))
谢谢!!