我正在使用带有连接框架的openapi3定义REST API,以下是openapy.yaml的外观。
.
.
openapi: 3.0.0
paths:
/add:
post:
operationId: manage_add
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
cust_data:
$ref: '#/components/schemas/test_data'
file:
format: binary
.
.
components:
schemas:
test_data:
type: object
required:
- uid
- port
- name
properties:
uid:
type: string
example: 5c6fc35ef926f1ef6174881e
port:
type: integer
example: 8081
name:
type: string
example: my_name
当我进行包含文件内容的curl请求时,将输出作为错误请求,类型为空
curl -X POST "http://0.0.0.0:5001/add" -H "accept: */*" -H "X-Auth: 3_KbYSYjy3m6AvTAt9dCJXhK66AW" -H "Content-Type: multipart/form-data" -F "cust_data={ "name": "my_name", "port": 8081, "userid": "5c6fc35ef926f1ef6174881e" }" -F "file=@fileadd.tar.gz;type=application/gzip"
我得到的答复是:
{
"detail": "'{ name: my_name, port: 8081, userid: 5c6fc35ef926f1ef6174881e }' is not of type 'object'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}
我的connexion和Flask的版本是: 连接== 2.4.0 Flask == 1.1.1
基本上我想编写一个API,它将从python像这样调用:
files = {'cust_data':(None, json.dumps(cust_data),'application/json'),
'file':(os.path.basename(tar_path),open(tar_path,'rb'),'application/octet-stream')
}
requests.post("https://localhost:5001/vpn_add",files=files,verify=False)