django rest framework:oscar api 身份验证不起作用

django rest frame work : oscarapi authentication is not working

当我通过 ios 调用 oscarapi 时,我遇到了一个奇怪的问题。它与 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.py

class CategoryListCustomd(generics.ListAPIView):
def get_queryset(self):
    queryset = Category.objects.all()
    return queryset
serializer_class = CustomCategorySerializer

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

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

并返回 "Authentication credentials were not provided." 错误。 在 url 中添加“/”解决了问题。

我想的原因是,301 重定向未在请求中发送授权 header。 希望这可能有所帮助