簡體   English   中英

未提供Django身份驗證憑據

[英]Django Authentication credentials were not provided

所以我正在使用Http文件使用rest_framework身份驗證進行GET請求

這是我使用的命令:

GET localhost:8000/api-admin/products
Authorization: Token 5e2cf6ddc7a0ff8fe03e4749d788a423f6640443

當我使用瀏覽器並轉到該鏈接時,它可以成功工作,但是當我使用HTTP文件或郵遞員時,我Authentication credentials were not provided. 錯誤

我也在設置文件中添加了代碼

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    )
}

我認為您必須在URL末尾添加尾隨/。

錯誤是我忘記在authentication_classes添加TokenAuthentication

authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)

在API文件中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM