我想使用POST謂詞在flask-restplus上對虛擬機執行操作,但當沒有主體時總是會產生400。Flask-restplus如何在沒有身體的情況下發帖
VM_ACTION_FIELDS = {
'vmActionId': fields.Integer(required=True, description='The vmActionId of the VmAction'),
'vmId': fields.Integer(required=True, description='The vmId of the VmAction'),
'status': fields.String(required=True, description='The status of the VmAction',
enum=['NEW', 'REQUESTED', 'IN_PROGRESS', 'ERROR', 'COMPLETED']),
'actionType': fields.String(required=True, description='The actionType of the VmAction',
enum=['STOP', 'RESTART']),
'createdAt': fields.DateTime(required=True,
description='The createdAt datetime of the VmAction'),
'completedAt': fields.DateTime(required=True,
description='The completedAt datetime of the VmAction'),
}
VM_ACTION_MODEL = api.model('VmAction', VM_ACTION_FIELDS)
[snip]
@vms_ns.route('/<int:vmId>/stop', endpoint='vmStop')
class VmStopView(Resource):
"""
Stop a VM
"""
@api.marshal_with(VM_ACTION_MODEL, code=202)
@api.doc(id='stopVm', description='Stop a Vm')
def post(self, vmId):
# do stuff
return vmAction, 202
結果是 { 「消息」:「瀏覽器(或代理)發送的請求,該服務器無法理解」。 }
如果我只是簡單地改變從發佈到獲得,它工作正常。但是,我真的很想使用POST動詞,因爲那是我需要遵循的自定義非CRUD操作的標準動詞。我是否用flask-restplus將自己繪製成一個角落?
注意:對於需要身體的操作,它可以正常工作。它唯一的無身體瓶 - restplus後操作,400空體錯誤。
是的,這就是它。我不需要將body設置爲{},但是如果我刪除了「header-Content」類型的應用程序/ json,它就起作用了!我看到你將它添加爲0.8.1里程碑。太棒了,謝謝。 –