Python Eve 框架身份验证未应用于选定的 API

标签 python rest authentication eve

我正在用 Python Eve 编写 API,为了实现身份验证,我遵循了 Python Eve Authentication 上编写的文档

我的认证类代码如下:-

__author__ = 'sappal'

from eve.auth import BasicAuth

class SampleAuth(BasicAuth):
  def check_auth(self, username, password, allowed_roles, resource, method):

    if method == 'GET' and resource == 'org':
      print "Inside GET Method for Org Resource"

    elif method == 'POST' and resource == 'org':
      print "Inside POST Method for Org Resource "

    elif method == 'GET' and resource == 'people':
      print "Inside GET Method for People Resource"

    elif method == 'POST' and resource == 'people':
      return True
    else:
      return username == 'admin' and password == 'secret'

正如代码所述,我正在对人员端点进行 POST 调用而无需身份验证{这就是我打算做的},但是当我对人员端点进行 POST 调用时 [http://127.0.0.1:5000/people]

我收到以下回复

{"_status": "ERR", "_error"
     {
       "message": "Please provide proper credentials", 
       "code": 401
     }
}

我的请求负载是:-

[
  {
    'firstname': 'Tushar',
    'lastname': 'Sappal',
    'email': 'testemailaddresshurray@gmail.com',
    'phonenumber': 123456789,
    'userid': '',
    'password': 'testtushar'
  }
]

我正在动态生成用户 ID,因此它不是在请求负载中传递的强制值。

请帮助和指导我,我做错了什么。

最佳答案

尝试为 people 资源将 public_methods 设置为 ['POST'](参见 docs )。或者您可以设置 PUBLIC_METHODS 但随后您将为所有 API 端点打开 POST 方法。

关于Python Eve 框架身份验证未应用于选定的 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30130196/

相关文章:

java - 使用 Spring boot CrudRepository 过滤数据

java - 在 Android 中使用 RestTemplate 使用 https REST WebService

c# - 如何伪造 Active Directory?

javascript - 使用变量中预设的密码登录系统

python - 逐个元素总结具有不同索引的两个 Pandas 数据帧

python - 根据单独系列的索引对 Pandas DataFrame 的列执行替换的最快方法是什么?

Tornado Web 应用程序中的 Python xmpp jabber 客户端

rest - ALPS 示例实现

linux - 如果发生转换错误,如何返回到应用程序而不检查pam中的其他方法

python - 删除错误 : 'setuptools' is a dependency of conda and cannot be removed from conda's operating environment