Created
June 9, 2021 22:21
-
-
Save nmathira/ee360a78416378e2f263099bfea7e5a4 to your computer and use it in GitHub Desktop.
Receiving data from an API, with and without verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def get_dog_fact(): | |
data = requests.get("https://some-random-api.ml/facts/dog") | |
if data.status_code == 200: | |
data = data.json() | |
return data["fact"] | |
else: | |
return f"Request Failed with status code: {data.status_code}" | |
def get_dog_img(): | |
headers = {'x-api-key': '203d078f-14a9-4835-8c17-c386b60cfdf0'} | |
data = requests.get("https://api.thedogapi.com/v1/images/search", headers=headers) | |
data = data.json() | |
return data[0]["url"] | |
if __name__ == '__main__': | |
# print(get_dog_fact()) | |
print(get_dog_img()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment