Python Eve Framework 身份验证未应用于选定的 API
Python Eve Framework Authentication not getting applied to selected APIs
我在 Python 前夕编写 API,为了实现身份验证,我遵循了 Python Eve Authentication
中编写的文档
我的认证Class代码如下:-
__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 前夕编写 API,为了实现身份验证,我遵循了 Python Eve Authentication
中编写的文档我的认证Class代码如下:-
__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 方法。