【问题标题】:django rest frame work : oscarapi authentication is not workingdjango rest 框架:oscar api 身份验证不起作用
【发布时间】:2017-04-20 14:07:12
【问题描述】:

当我通过 ios 调用 oscarapi 调用时,我遇到了一个奇怪的问题。它与邮递员一起工作正常。但是当我通过 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

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题,在查看通话记录时,我发现我的通话是 301 重定向如下 -

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-29
      • 2017-09-26
      • 2017-11-02
      • 2019-02-20
      • 1970-01-01
      • 2019-03-01
      • 2021-12-21
      • 1970-01-01
      相关资源
      最近更新 更多