【问题标题】:Python Flask Flasgger (Swagger) webargs - List of Strings in HTTP PUT bodyPython Flask Flasgger (Swagger) webargs - HTTP PUT 正文中的字符串列表
【发布时间】:2018-04-02 03:47:15
【问题描述】:

我使用flask、flasgger(由yml文件定义的swagger)和webargs创建了一个python web API:

@app.route('/api/set/', methods=['PUT'])
@swag_from('swagger/put_community_sets.yml')
@use_kwargs({'community_set': fields.List(fields.Str(), 
    location='json', required=True)})
def put_community_set(community_set):
    print 'community_set to add: ' + str(community_set)

put_community_sets.yml:

tags:
 - put community set API
parameters:
 - name: body
   in: body
  schema:
    id: put_community_set
    required:
      - community_set
    properties:
      community_set:
        type: array
        items:
          type: string
        description: the community set to be added
  responses:
     '200':
       description: added a new community set

作为测试,我运行我的烧瓶应用程序并发送 HTTP PUT-

header = 内容类型,应用程序/json

body = ["test1", "test2", "test3"]

我得到: 422 无法处理的实体 该请求格式正确,但由于语义错误而无法执行。

我猜测 yml 文件中的 swagger 定义、@use_kwargs 参数或我的测试 PUT 有问题。

【问题讨论】:

  • 你是如何发送请求的?

标签: python flask swagger flasgger webargs


【解决方案1】:

所以我自己想通了。

必须使用: {"community_set": ["test1", "test2", "test3"]}

不仅仅是: ["test1", "test2", "test3"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多