👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I"m developing an API using Django Rest Framework. I"m trying to list or create an "Order" object, but when i"m trying to access the console gives me this error:
{"detail": "Authentication credentials were not provided."}
Views:
from django.shortcuts import render
from rest_framework import viewsets
from django.contrib.auth.models import User
from rest_framework.renderers import JSONRenderer, YAMLRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
from order.models import *
from API.serializers import *
from 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 my URLs:
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
from django.utils.functional import curry
from django.views.defaults import *
from rest_framework import routers
from 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 then I"m using this command in the console:
curl -X GET http://127.0.0.1:8000/api/orders/ -H "Authorization: Token 12383dcb52d627eabd39e7e88501e96a2sadc55"
And the error say:
{"detail": "Authentication credentials were not provided."}
👻 Read also: what is the best laptop for engineering students?
Django Rest Framework - Authentication credentials were not provided __del__: Questions
How can I make a time delay in Python?
5 answers
I would like to know how to put a time delay in a Python script.
Answer #1
import time
time.sleep(5) # Delays for 5 seconds. You can also use a float value.
Here is another example where something is run approximately once a minute:
import time
while True:
print("This prints once a minute.")
time.sleep(60) # Delay for 1 minute (60 seconds).
Answer #2
You can use the sleep()
function in the time
module. It can take a float argument for sub-second resolution.
from time import sleep
sleep(0.1) # Time in seconds
Django Rest Framework - Authentication credentials were not provided __del__: Questions
How to delete a file or folder in Python?
5 answers
How do I delete a file or folder in Python?
Answer #1
os.remove()
removes a file.os.rmdir()
removes an empty directory.shutil.rmtree()
deletes a directory and all its contents.
Path
objects from the Python 3.4+ pathlib
module also expose these instance methods:
pathlib.Path.unlink()
removes a file or symbolic link.pathlib.Path.rmdir()
removes an empty directory.
We hope this article has helped you to resolve the problem. Apart from Django Rest Framework – Authentication credentials were not provided, check other __del__-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Django Rest Framework – Authentication credentials were not provided
- Deutsch Django Rest Framework – Authentication credentials were not provided
- Français Django Rest Framework – Authentication credentials were not provided
- Español Django Rest Framework – Authentication credentials were not provided
- Türk Django Rest Framework – Authentication credentials were not provided
- Русский Django Rest Framework – Authentication credentials were not provided
- Português Django Rest Framework – Authentication credentials were not provided
- Polski Django Rest Framework – Authentication credentials were not provided
- Nederlandse Django Rest Framework – Authentication credentials were not provided
- 中文 Django Rest Framework – Authentication credentials were not provided
- 한국어 Django Rest Framework – Authentication credentials were not provided
- 日本語 Django Rest Framework – Authentication credentials were not provided
- हिन्दी Django Rest Framework – Authentication credentials were not provided
Abu Dhabi | 2023-03-24
I was preparing for my coding interview, thanks for clarifying this - Django Rest Framework – Authentication credentials were not provided in Python is not the simplest one. I just hope that will not emerge anymore
Warsaw | 2023-03-24
Thanks for explaining! I was stuck with Django Rest Framework – Authentication credentials were not provided for some hours, finally got it done 🤗. I am just not quite sure it is the best method
Tallinn | 2023-03-24
Thanks for explaining! I was stuck with Django Rest Framework – Authentication credentials were not provided for some hours, finally got it done 🤗. Will get back tomorrow with feedback