(self,
            content='',
            mimetype=None,
            content_type=settings.DEFAULT_CONTENT_TYPE)
Error response generator. Returns a Django HttpResponse with status
        401 and the approproate headers set. See Django documentation for details.
        https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.__init__

        **Kwargs:**

        * *content:* See Django docs. *Default ''*
        * *mimetype:* See Django docs. *Default None*
        * *content_type:* See Django docs. *Default DEFAULT_CONTENT_TYPE*
Error response generator. Returns a Django HttpResponse with status
        401 and the approproate headers set. See Django documentation for details.
        https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.__init__
Error response generator . Returns a Django HttpResponse with status 401 and the approproate headers set . See Django documentation for details . https : // docs . djangoproject . com / en / dev / ref / request - response / #django . http . HttpResponse . __init__
def error_response(self,
            content='',
            mimetype=None,
            content_type=settings.DEFAULT_CONTENT_TYPE):
        """Error response generator. Returns a Django HttpResponse with status
        401 and the approproate headers set. See Django documentation for details.
        https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.__init__

        **Kwargs:**

        * *content:* See Django docs. *Default ''*
        * *mimetype:* See Django docs. *Default None*
        * *content_type:* See Django docs. *Default DEFAULT_CONTENT_TYPE*

        """
        response = HttpResponse(
            content=content,
            mimetype=mimetype,
            content_type=content_type)
        if not self.attempted_validation:
            response['WWW-Authenticate'] = 'Bearer realm="%s"' % REALM
            response.status_code = 401
            return response
        else:
            if self.error is not None:
                error = getattr(self.error, "error", "invalid_request")
                error_description = self.error.message
            else:
                error = "invalid_request"
                error_description = "Invalid Request."
            header = [
                'Bearer realm="%s"' % REALM,
                'error="%s"' % error,
                'error_description="%s"' % error_description]
            if isinstance(self.error, InsufficientScope):
                header.append('scope=%s' % ' '.join(self.authorized_scope))
                response.status_code = 403
            elif isinstance(self.error, InvalidToken):
                response.status_code = 401
            elif isinstance(self.error, InvalidRequest):
                response.status_code = 400
            else:
                response.status_code = 401
            response['WWW-Authenticate'] = ', '.join(header)
            return response
def error_response ( self , content = '' , mimetype = None , content_type = settings . DEFAULT_CONTENT_TYPE ) : response = HttpResponse ( content = content , mimetype = mimetype , content_type = content_type ) if not self . attempted_validation : response [ 'WWW-Authenticate' ] = 'Bearer realm="%s"' % REALM response . status_code = 401 return response else : if self . error is not None : error = getattr ( self . error , "error" , "invalid_request" ) error_description = self . error . message else : error = "invalid_request" error_description = "Invalid Request." header = [ 'Bearer realm="%s"' % REALM , 'error="%s"' % error , 'error_description="%s"' % error_description ] if isinstance ( self . error , InsufficientScope ) : header . append ( 'scope=%s' % ' ' . join ( self . authorized_scope ) ) response . status_code = 403 elif isinstance ( self . error , InvalidToken ) : response . status_code = 401 elif isinstance ( self . error , InvalidRequest ) : response . status_code = 400 else : response . status_code = 401 response [ 'WWW-Authenticate' ] = ', ' . join ( header ) return response