rest_framework_swagger installation - HTTP 401 Unauthorized

zabitstack

I have installed rest_framework_swagger successfully, after that I set url in urls.py file project:

from django.contrib import admin
from django.urls import path, include, re_path
from unimiproject.router import router
from rest_framework.authtoken import views
from rest_framework.schemas import get_schema_view
from django.views.generic import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    re_path(r"^appjud/",include("appjud.urls")),
    path('api/', include(router.urls)),
    path('api-token-auth/', views.obtain_auth_token, name='api-token-auth'),
    path('openapi/', get_schema_view(
        title="School Service",
        description="API developers hpoing to use our service"
    ), name='openapi-schema'),
    path('docs/', TemplateView.as_view(
        template_name='documentation.html',
        extra_context={'schema_url':'openapi-schema'}
    ), name='swagger-ui')

]

but if I browse http://172.18.0.1:7000/openapi/ I get this:

Schema

GET /openapi/

HTTP 401 Unauthorized
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
WWW-Authenticate: Token

{
    "detail": "Authentication credentials were not provided."
}

Why do I get "Authentication credentials were not provided"? It should show me schema of all apis not to test they.

ShiBil PK

Try using permission_classes=(permissions.AllowAny,) to your code then the user not needed a username and password to assess your documentation

from rest_framework import permissions
from drf_yasg import openapi

path('openapi/',get_schema_view(
    openapi.Info(
        title="School Service",
        description="API developers hoping to use our service",
        contact=openapi.Contact(email="[email protected]"),
        license=openapi.License(name="Proprietary Software"),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

HTTP 401 Unauthorized error occurs in Spring Boot test

Http failure response for http url: 401 Unauthorized

Sending requests to rest webServices from swagger ends to 401 and unauthorized

403 Forbidden vs 401 Unauthorized HTTP responses

Rest_Framework APIClient tests return 401 Unauthorized with Token Authentication

HTTPError: HTTP Error 401: Unauthorized for sendgrid integration with python

HTTP/1.1 401 Unauthorized when uploading binary on bintray

HTTP Error 401: Unauthorized using urllib.request.urlopen

Android NTLM getting HTTP/1.1 401 Unauthorized

401 unauthorized page for swagger?

Django Rest Framework: HTTP 401 Unauthorized error

HTTP response '401: Unauthorized' using NTLM with Wildfly

Why does Authorize attribute not cause HTTP 401 for unauthorized requests with JWTs

Julia API Call to Alpaca trading receives HTTP/1.1 401 Unauthorized

Partner Central rest api 401 unauthorized access

jBPM Business Central rest api 401 unauthorized

GitHub Actions with hub results in Unauthorized (HTTP 401) Bad credentials

SOAP client basic auth: HTTP response '401: Unauthorized'

Python Linkedin API OAuth2 HTTP Error 401: Unauthorized

Solr HTTP error: Unauthorized (401)

"HTTP Error 401: Unauthorized" when querying youtube api for playlist with python

HTTP/1.1 401 Unauthorized Error on curl request - heroku

Parse REST api Logout 401 unauthorized

Azure AD - HTTP/1.1 401 Unauthorized - Windows Service

catch a 401 Unauthorized http response using jquery ajax

Unauthorized (HTTP 401) R omdbapi

401 UnAuthorized - This request requires HTTP authentication - Payara/Glassfish

Chat bot framework 401 unauthorized issue

Angular Rest API call returning 401 Unauthorized