eve REST API 以及如何 post 基于角色的身份验证的角色列表

eve REST API and how to post a role list for role based authentication

我正在尝试像 http://python-eve.org/tutorials/account_management.html#b-user-roles-access-control

中一样重新创建基于角色的身份验证

API 是 运行,我可以在没有角色的情况下添加帐户,但是当我像上面那样实现角色时 link 并尝试 post通过 Pycharms REST 客户端角色我得到:

{"_status": "ERR", "_issues": 
  {"roles": "must be of list type"}, 
  "_error": 
    {"message": "Insertion failure: 1 document(s) contain(s) error(s)", "code": 422}}

我尝试了很多不同的方法来 post 角色,例如 roles[]=user 的变体,但是如果我在 REST 客户端的输入字段中输入除了角色之外的任何其他内容,我会得到一些东西像 "no field roles[], roles required" 等...

有人可以帮我列出 post 个角色吗?

PS:当我尝试使用 "Advanced REST client" 或 "POSTMAN" 等其他内容时,我得到:

File "C:\Python27\lib\site-packages\flask\app.py", line 1465, in find_handler
    handler = handler_map.get(cls)
AttributeError: 'function' object has no attribute 'get'
127.0.0.1 - - [04/Nov/2016 14:29:42] "POST /accounts HTTP/1.1" 500 -

如果您使用与示例相同的模式,那么角色键必须包含角色列表,而不是字符串。我不知道您究竟是如何发送请求的,但我猜您将此参数添加到 URL 是不正确的。根据提供的架构,您应该发送 POST 带有有效负载的请求,例如:

{"username":"User","password":"0000","roles":["user","superuser"]}

另外记得发送内容类型header:

Content-Type: application/json

如果您使用 PyCharm REST 客户端,您的配置应该如下所示