Django rest framework 在CoreAPI中使用令牌身份验证时遇到问题

Django rest framework 在CoreAPI中使用令牌身份验证时遇到问题,django-rest-framework,core-api,Django Rest Framework,Core Api,我正在使用django的rest_框架库为django应用程序构建API。一切都很顺利,我能够像预期的那样通过curl命令访问我的API 现在,我想通过使用CoreAPI的客户端库的形式使事情变得更加优雅 我可以执行如下基本身份验证: auth = coreapi.auth.BasicAuthentication(username=user, password=password) client = coreapi.Client(auth=auth) 我可以很好地访问API的模式 但是,我想使用

我正在使用django的rest_框架库为django应用程序构建API。一切都很顺利,我能够像预期的那样通过curl命令访问我的API

现在,我想通过使用CoreAPI的客户端库的形式使事情变得更加优雅

我可以执行如下基本身份验证:

auth = coreapi.auth.BasicAuthentication(username=user, password=password)
client = coreapi.Client(auth=auth)
我可以很好地访问API的模式

但是,我想使用我的令牌身份验证(通过rest_framework.tokenauthenticationon)(通过curl可以正常工作)如果出现错误,我的代码如下所示:

token = 'Token abc12345'
#tried the following:
#token = 'abc12345'
#token = 'Authorization: Token abc12345'
auth = coreapi.auth.TokenAuthentication(token=token)
client = coreapi.Client(auth=auth)
尝试访问架构时,我得到:

coreapi.exceptions.ErrorMessage: <Error: 401 UNAUTHORIZED>
    detail: "Authentication credentials were not provided."
coreapi.exceptions.error消息:
详细信息:“未提供身份验证凭据。”
文档显示TokenAuthentication需要模式和令牌作为参数,但是示例显示了使用JWT而不是djangos rest_framework.TokenAuthentication的TokenAuthentication


任何建议都将不胜感激

我也有同样的问题。修复方法是为coreapi.auth.TokenAuthentication设置一个“scheme='Token'”参数。所以,像这样的东西可能适合你:

token = 'abc12345' # don't put the word 'Token' in front. 
auth = coreapi.auth.TokenAuthentication(scheme='Token', token=token)
client = coreapi.Client(auth=auth)