Composing requests with the necessary authentication

Now we will compose and send an HTTP request to retrieve the first page of the notifications without authentication credentials. The code file for the sample is included in the restful_python_2_03_01 folder, in the Flask01/cmd317.txt file:

    http GET ":5000/service/notifications/?page=1"

The following is the equivalent curl command. The code file for the sample is included in the restful_python_2_03_01 folder, in the Flask01/cmd318.txt file:

    curl -iX GET "localhost:5000/service/notifications/?page=1"

We will receive a 401 Unauthorized status code in the response header. The following lines show a sample response:

    HTTP/1.0 401 UNAUTHORIZED
    Content-Length: 19
    Content-Type: text/html; ...

Get Hands-On RESTful Python Web Services - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.