django休息框架:oscar api认证不起作用

问题描述 投票:0回答:1

当我通过ios拨打oscar api电话时,我遇到了一个奇怪的问题。它与POSTMAN一起工作正常。但是当我通过xcode调用时,它会显示以下错误。

HTTP/1.1 401 Authorization Required
Connection: Keep-Alive
Content-Type: application/json
Server: Apache/2.4.7 (Ubuntu)
Allow: GET, HEAD, OPTIONS
Vary: Accept,Authorization,Cookie
Date: Thu, 20 Apr 2017 13:55:13 GMT
X-Frame-Options: SAMEORIGIN
Www-Authenticate: Bearer realm="api"
Keep-Alive: timeout=5, max=100
Transfer-Encoding: Identity

{"detail":"Authentication credentials were not provided."}

我发送标题授权如下。这在邮递员工作正常。

 Authorization: Bearer iw7cGIz4uF036j7VbpGCXbceCCbbD1

我的urls.py

url(r'^api/v1/categories', views.CategoryListCustom.as_view(), name='category-list')

views.朋友

class CategoryListCustomd(generics.ListAPIView):
def get_queryset(self):
    queryset = Category.objects.all()
    return queryset
serializer_class = CustomCategorySerializer
django django-rest-framework django-authentication django-oscar
1个回答
1
投票

我有同样的问题,在检查通话记录时,我发现我的电话是301重定向如下 -

"GET /api/v1/basket HTTP/1.1" 301 0
"GET /api/v1/basket/ HTTP/1.1" 200 401

并返回“未提供身份验证凭据”。错误。在url中附加“/”解决了这个问题。

我认为,301重定向不在请求中发送授权头。希望这可能有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.