TypeError: defined function got an unexpected keyword argument 'many
TypeError: defined function got an unexpected keyword argument 'many
我的 python 应用程序有问题。我正在学习 posted 的教程:https://auth0.com/blog/developing-restful-apis-with-python-and-flask/
我尝试通过电源post数据到应用程序-shell:
$params = @{amount=80; description='test_doc'}
Invoke-WebRequest -Uri http://127.0.0.1:5000/incomes -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json"
当我 运行 PS 脚本时,我的 python 应用程序出现错误:
TypeError: make_income() got an unexpected keyword argument 'many'
我的代码如下所示:
from marshmallow import post_load
from .transaction import Transaction, TransactionSchema
from .transaction_type import TransactionType
class Income(Transaction):
def __init__(self, description, amount):
super(Income, self).__init__(description, amount, TransactionType.INCOME)
def __repr__(self):
return '<Income(name={self.description!r})>'.format(self=self)
class IncomeSchema(TransactionSchema):
@post_load
def make_income(self, data):
return Income(**data)
我如何将参数 many
放入我的函数中?这是棉花糖问题吗?
我尝试添加 **
但我得到同样的错误:
def make_income(self, **data):
return Income(**data)
我也试过了
def make_income(self, data, **kwargs):
return Income(**data)
这是我的 transaction.py 文件
import datetime as dt
from marshmallow import Schema, fields
class Transaction():
def __init__(self, description, amount, type):
self.description = description
self.amount = amount
self.created_at = dt.datetime.now()
self.type = type
def __repr__(self):
return '<Transaction(name={self.description!r})>'.format(self=self)
class TransactionSchema(Schema):
description = fields.Str()
amount = fields.Number()
created_at = fields.Date()
type = fields.Str()
在 marsmallow 3 中,装饰方法(pre/post_dump/load,...)必须包含未知的 kwargs。
class IncomeSchema(TransactionSchema):
@post_load
def make_income(self, data, **kwargs):
return Income(**data)
(您可能需要将此事通知博客作者。)
我的 python 应用程序有问题。我正在学习 posted 的教程:https://auth0.com/blog/developing-restful-apis-with-python-and-flask/
我尝试通过电源post数据到应用程序-shell:
$params = @{amount=80; description='test_doc'}
Invoke-WebRequest -Uri http://127.0.0.1:5000/incomes -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json"
当我 运行 PS 脚本时,我的 python 应用程序出现错误:
TypeError: make_income() got an unexpected keyword argument 'many'
我的代码如下所示:
from marshmallow import post_load
from .transaction import Transaction, TransactionSchema
from .transaction_type import TransactionType
class Income(Transaction):
def __init__(self, description, amount):
super(Income, self).__init__(description, amount, TransactionType.INCOME)
def __repr__(self):
return '<Income(name={self.description!r})>'.format(self=self)
class IncomeSchema(TransactionSchema):
@post_load
def make_income(self, data):
return Income(**data)
我如何将参数 many
放入我的函数中?这是棉花糖问题吗?
我尝试添加 **
但我得到同样的错误:
def make_income(self, **data):
return Income(**data)
我也试过了
def make_income(self, data, **kwargs):
return Income(**data)
这是我的 transaction.py 文件
import datetime as dt
from marshmallow import Schema, fields
class Transaction():
def __init__(self, description, amount, type):
self.description = description
self.amount = amount
self.created_at = dt.datetime.now()
self.type = type
def __repr__(self):
return '<Transaction(name={self.description!r})>'.format(self=self)
class TransactionSchema(Schema):
description = fields.Str()
amount = fields.Number()
created_at = fields.Date()
type = fields.Str()
在 marsmallow 3 中,装饰方法(pre/post_dump/load,...)必须包含未知的 kwargs。
class IncomeSchema(TransactionSchema):
@post_load
def make_income(self, data, **kwargs):
return Income(**data)
(您可能需要将此事通知博客作者。)