python - Django Rest Framework - Authentication credentials were not provided -
i'm developing api using django rest framework. i'm trying list or create "order" object, when i'm trying access console gives me error:
{"detail": "authentication credentials not provided."}
views:
from django.shortcuts import render rest_framework import viewsets django.contrib.auth.models import user rest_framework.renderers import jsonrenderer, yamlrenderer rest_framework.response import response rest_framework.views import apiview order.models import * api.serializers import * rest_framework.permissions import isauthenticated class orderviewset(viewsets.modelviewset): model = order serializer_class = orderserializer permission_classes = (isauthenticated,)
serializer:
class orderserializer(serializers.hyperlinkedmodelserializer): class meta: model = order fields = ('field1', 'field2')
and urls:
# -*- coding: utf-8 -*- django.conf.urls import patterns, include, url django.conf import settings django.contrib import admin django.utils.functional import curry django.views.defaults import * rest_framework import routers api.views import * admin.autodiscover() handler500 = "web.views.server_error" handler404 = "web.views.page_not_found_error" router = routers.defaultrouter() router.register(r'orders', ordersviewset) urlpatterns = patterns('', url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^api-token-auth/', 'rest_framework.authtoken.views.obtain_auth_token'), url(r'^api/', include(router.urls)), )
and i'm using command in console:
curl -x http://127.0.0.1:8000/api/orders/ -h 'authorization: token 12383dcb52d627eabd39e7e88501e96a2sadc55'
and error say:
{"detail": "authentication credentials not provided."}
if runnig django on apache using mod_wsgi have add
wsgipassauthorization on
in httpd.conf. otherwise authorization header stripped out mod_wsgi.
Comments
Post a Comment