django rest frame work:oscarapi身份验证不起作用

时间:2017-04-20 14:07:13

标签: django django-rest-framework django-authentication django-oscar

当我通过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."}

我发送标题authrization如下。这在邮递员工作得很好。

 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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

相关问题