遇到Python CoreAPI身份验证问题

时间:2017-08-18 14:58:48

标签: python core-api

我已经尝试了两种记录的身份验证方法,但两者都产生403 Forbidden,detail:"未提供身份验证凭据。"

auth = coreapi.auth.TokenAuthentication(
scheme='Token', token='token')

auth = coreapi.auth.BasicAuthentication(
username='user',
password='password')

url = 'http://127.0.0.1:8000/schema/'
client = coreapi.Client(auth=auth)
schema = client.get(url)

1 个答案:

答案 0 :(得分:0)

根据coreapi.auth.BasicAuthenticationcoreapi.auth.TokenAuthentication here的源代码,您需要按如下方式实例化身份验证对象:

auth = coreapi.auth.TokenAuthentication(
scheme='Token', token='token', domain='domain')

auth = coreapi.auth.BasicAuthentication(
username='user',
password='password',
domain='domain'  
)