API autenticação de chave com solicitações
API A autenticação baseada em chave funciona de forma semelhante à autenticação básica, mas você deve incluir uma chave API exclusiva usando um cabeçalho de solicitação ou um parâmetro URL para solicitações autenticadas. Vamos explorar as duas abordagens.
É bom você saber:
- O pacote
requests
já foi importado. - Use a chave/token API
8apDFHaNJMxy8Kt818aa6b4a0ed0514b5d3
para se autenticar.
Este exercício faz parte do curso
Introdução a APIs em Python
Exercício interativo prático
Experimente este exercício preenchendo este código de exemplo.
# Create a dictionary containing the API key using the correct key-value combination
params = {____: ____}
# Add the dictionary to the requests.get() call using the correct function argument
response = requests.get('http://localhost:3000/albums', ____=params)
if(response.status_code == 200):
print("Success!")
elif(response.status_code == 401):
print('Authentication failed')
else:
print('Another error occurred')