Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (19.9k points)

Hello I am trying to test Token Authentication i have implemented with DRF using httpie.

The following command:

http GET 127.0.0.1:8000/api/projects/ 'Authorization: Token b453919a139448c5891eadeb14bf1080a2624b03'

yields the following 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,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]

        [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]

        [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]

        [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]http: error: argument REQUEST_ITEM: "Token" is not a valid value

So i decided to differ from the tutorial and made my request like this

http GET 127.0.0.1:8000/api/projects/ 'Authorization:b453919a139448c5891eadeb14bf1080a2624b03'

The following message was returned

HTTP/1.0 401 Unauthorized

Allow: GET, POST, HEAD, OPTIONS

Content-Type: application/json

Date: Thu, 03 Nov 2016 09:52:05 GMT

Server: WSGIServer/0.1 Python/2.7.10

Vary: Accept

WWW-Authenticate: Token

X-Frame-Options: SAMEORIGIN

  {

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

  }

Any assistance offered would be great. I am running on local machine at home.

1 Answer

0 votes
by (25.1k points)

Use double quotes in the place of single quotes.

For curl use the command below

curl -H "Authorization: Token b453919a139448c5891eadeb14bf1080a2624b03" http://127.0.0.1:8000/api/projects/

For HTTPie use

http GET http://127.0.0.1:8000/api/projects/ "Authorization: Token b453919a139448c5891eadeb14bf1080a2624b03"

Related questions

0 votes
1 answer
asked Mar 8, 2021 in Web Technology by Rekha (2.2k points)
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...