requests Method to Retrieve
Coddy의 Python으로 배우는 API 코스 레슨 — 10개 중 5번째.
API에서 정보를 검색하려면 .get()이라는 메서드를 사용해야 합니다.
이 get() 메서드는 URL과 API 키를 매개변수로 받습니다.
참고: 때로는 API 키가 필요하지 않을 수도 있습니다. 이는 API 서버에 따라 다릅니다.
그래서 코드는 다음과 같습니다:
import requests
response = requests.get("https://www.API_URL.com", "API_KEY_IF_NECESSARY")
print(response)여기서는 응답에 더 쉽게 접근할 수 있도록 메서드를 response 변수에 저장하고 있습니다.
챌린지
쉬움"https://reqres.in"으로 get 요청을 보내고 이를 response 변수에 저장하세요.
직접 해보기
import requests
# Write code here
# Don't change below this line
print(response.status_code)
print(response.url)Python으로 배우는 API의 모든 레슨
2API in Python
requests Library for APIrequests Method to Retrieverequests Method to Send DataManipulating requests Response3Weather Fetch API Program
API Connection to ServerGET Request to ServerDisplaying Appropriate Results