BaşlayınÜcretsiz Başlayın

API key authentication with requests

API key-based authentication functions similarly to Basic Authentication, but you must include a unique API key using either a request header or a URL parameter for authenticated requests. Let's explore both approaches.

Good to know:

  1. The requests package has already been imported.
  2. Use the API key/token 8apDFHaNJMxy8Kt818aa6b4a0ed0514b5d3 to authenticate.

Bu egzersiz

Introduction to APIs in Python

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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')
Kodu Düzenle ve Çalıştır