requests paketini kullanma
API’leri urllib ile entegre etmek, yanıtları kodlama/çözme gibi birçok ek işle ilgilenmen gerektiği için ayrıntılı ve karmaşık bir koda yol açabilir.
urllib’ye alternatif olarak, requests Python paketi API entegrasyonunu daha basit hale getirir. requests pek çok işlevi kutudan çıktığı gibi sunar; bu da kodunu yazmayı ve okumayı çok daha kolaylaştırır. Haydi aynı egzersizi bu kez requests paketiyle deneyelim.
Unutma, önceki egzersizde olduğu gibi, Lyrics API için URL http://localhost:3000/lyrics.
Bu egzersiz, kursun bir parçasıdır
Python ile API'lere Giriş
Egzersiz talimatları
requestspaketini içe aktar.http://localhost:3000/lyricsURL’sinirequests.getyöntemine geçir.- Yanıt metnini yazdır.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
# Import the requests package
import ____
# Pass the API URL to the get function
response = requests.get(____)
# Print out the text attribute of the response object
print(response.____)