Token Authentication Django Rest Framework HTTPie Error


Hello guys I am trying to test Token Authentication i have implemented with Django Rest Framework using httpie as per your tutorial .

My Command:
http 'Authorization: Token 144d89221a3dcdefa40e2856c3916a598e7c35c7'

Getting this error :

usage: http [–json] [–form] [–pretty {all,colors,format,none}]
[–style STYLE] [–print WHAT] [–headers] [–body] [–verbose]
[–all] [–history-print WHAT] [–stream] [–output FILE]
[–download] [–continue]
[–session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
[–auth USER[:PASS]] [–auth-type {basic,digest}]
[–proxy PROTOCOL:PROXY_URL] [–follow]
[–max-redirects MAX_REDIRECTS] [–timeout SECONDS]
[–check-status] [–verify VERIFY]
[–ssl {ssl2.3,tls1,tls1.1,tls1.2}] [–cert CERT]
[–cert-key CERT_KEY] [–ignore-stdin] [–help] [–version]
[–traceback] [–default-scheme DEFAULT_SCHEME] [–debug]
http: error: argument REQUEST_ITEM: “Token” is not a valid value

This is my VIEWS FILE

from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated

class HelloView(APIView):
	permission_classes = (IsAuthenticated,)

	def get(self,request):
		content = {'message': 'Hello, World!'}
		return Response(content)

This is my URLS File

from django.contrib import admin
from django.urls import path
from core import views

urlpatterns = [
    path('hello/', views.HelloView.as_view(), name='hello'),

(Vitor Freitas) #2

Try double quotes instead

http "Authorization: Token 144d89221a3dcdefa40e2856c3916a598e7c35c7"


Still getting http: error: argument REQUEST_ITEM: "Token" is not a valid value

I try it both

http "Authorization: Token d4be4d411775230c1c8eed7b3bf9fb3e3a9510d9"

http 'Authorization: Token d4be4d411775230c1c8eed7b3bf9fb3e3a9510d9'

I can also generate new token key but still not work.


Getting this new one error

http: error: ConnectionError: HTTPConnectionPool(host='', port=8000): Max retries exceeded with url: /hello/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0262FD70>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it')) while doing GET request to URL: