如何解决将 Marshmallow 中的值更改为 null,Python [PUT] 请求
Marshmallow 非常新,并且遇到了在向 API 发送 PUT 请求时将数据库中的值更新为空的问题。这是我的架构的删节版:
class FeatureSchema(Schema):
id = mfields.Integer()
name = mfields.String()
description = mfields.String()
status = mfields.String()
fields = mfields.List(mfields.String)
feature_file = mfields.Int()
type = mfields.String()
imputation = mfields.Integer()
scaling = mfields.String(allow_none=True)
和我的更新功能方法:
def __init__(self):
self.mm_schema = FeatureSchema()
def update(self,id,name=None,description=None,fields=None,feature_file=None,imputation=None,template_type_id=None,scaling=None
none_values_to_set=None):
feature = drop_keys_with_none_or_empty_values(locals())
if none_values_to_set:
for key in none_values_to_set:
if key in allowed_attributes:
feature[key] = None
url = "{}/api/feature/".format(self._base_url)
return self._put(url,self.mm_schema.dump(feature))
我希望能够将值更新为无,这在 self._put 方法之前工作正常。架构转储按需要发生,但 _put 方法出错并显示以下错误:
>>> bc.update(id=1010,scaling=None)
Out[4]: {'error': "{'scaling': ['Field may not be null.']}"}
我正在使用 python requests 库来创建请求。 棉花糖 3.5.0 Python 3.6
如果我需要添加更多信息,请告诉我,并提前致谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。