【问题标题】:Having Trouble with Authentication for Python CoreAPIPython CoreAPI 的身份验证遇到问题
【发布时间】:2018-01-27 07:40:32
【问题描述】:

我已经尝试了两种记录在案的身份验证方法,但都产生 403 Forbidden,详细信息:“未提供身份验证凭据。”

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)

【问题讨论】:

    标签: python core-api


    【解决方案1】:

    基于coreapi.auth.BasicAuthenticationcoreapi.auth.TokenAuthenticationhere的源码,需要实例化认证对象如下:

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

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

    【讨论】:

    • 您好 MedAli,感谢您的 cmets。我尝试了您对我的身份验证的调整,但仍然收到“未提供身份验证凭据”。尝试检索架构时。
    • @DavidG 使用请求而不是更好更易于使用。 docs.python-requests.org/en/master
    • ... 奇怪的是,我使用的身份验证服务于对格式为 client.get(get_document_url) 的其他请求进行身份验证,返回一个 OrderDict。 (没有身份验证的相同请求返回“未提供身份验证凭据。”)因此身份验证似乎适用于其他 url,但不适用于检索架构 ...
    • @DavidG 也许这是一个许可问题?因为我无法重现错误,所以我无能为力..
    猜你喜欢
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    相关资源
    最近更新 更多