0

I am doing a coding challenge, and I have to complete it. The challenge is to use API endpoint to get the poets data.

The available data is

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "data": [
        {
            "2015": "Juan Felipe Herrera",
            "2017": "Tracy K. Smith",
            "2019": "Joy Harjo"
        }
    ]
}

When I open it in incognito mode, This is the output

GET /api/examples/poets/
HTTP 403 Forbidden
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

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

API link is this. Now all I have in details is my UserName, Password, and API key. No other information, including what should be the label with API key, for-example some people use "Authorization", "X-auth" etc.

My Code tries so far are

def get_poet_names(parameters): #can not change this func name, parameters seems to be None in test cases
    # your code goes here!

    url = "https://www.stackmaps.com/api/examples/poets/"
    print(get)

    resp = get(url, auth=('username', 'pass'), params={'parameters', parameters})

    print(resp)

And

import urllib.request
import json

serviceurl = "https://www.stackmaps.com/api/examples/poets/"

with urllib.request.urlopen(serviceurl) as uh:
    data = uh.read()
    print(data)

And

from requests.auth import HTTPBasicAuth
import  requests


url = 'https://www.stackmaps.com/api/examples/poets/'

response = requests.get(url, auth=HTTPBasicAuth('myusername', 'mypass'))


print(response)

And adding {"Authorization": "<APIKEY"} like in this answer.

All I am getting is a <Response [403]>.

How to solve it. Thanks.

Ahmad Anis
  • 2,322
  • 4
  • 25
  • 54

0 Answers0