Request API data using Python in 8 minutes! ↩️

Request API data using Python in 8 minutes! ↩️

HomeOther ContentRequest API data using Python in 8 minutes! ↩️
ChannelPublish DateThumbnail & View CountActions
Channel AvatarPublish Date not found Thumbnail
0 Views
#python #pythonprogramming #pythontutorial
https://pokeapi.co/

00:00:00 Pokeapi intro
00:00:40 import requests
00:01:09 pip install requests
00:01:44 url
00:03:17 response.get(url)
00:03:35 response.status_code
00:06:22 display API data

# How to connect to an API using Python
import requests

base_url = /”https://pokeapi.co/api/v2//”

def get_pokemon_info(name):
url = f/”{base_url}/pokemon/{name}/”
response = requests.get(url)

if response.status_code == 200:
pokemon_data = response.json()
return pokemon_data
else:
print(f/”Failed to retrieve data {response.status_code}/”)

pokemon_name = /”pikachu/”
pokemon_info = get_pokemon_info(pokemon_name)

if pokemon_info:
print(f/”Name: {pokemon_info[/”name/”].capitalize()}/”)
print(f/”Id: {pokemon_info[/”id/”]}/”)
print(f/”Height: {pokemon_info[/”height/”]}/”)
print(f/”Weight: {pokemon_info[/”weight/”]}/”)

Please take the opportunity to connect and share this video with your friends and family if you find it useful.