Omanshu
Omanshu

Reputation: 11

PokeAPI's sprites are not getting loaded

When I try to load the sprites of various Pokemons using PokeAPI in python, nothing shows up.

Note: It was working when I last tested my application a few months ago.

The link which I try to load(in my kivyMD application through AsyncImage widget):


https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{id of the Pokemon}.png

I have also tried loading it using the requests module using the get function (just to check whether the problem is with the library or with the API), but I got the same results :(

Can someone please help me out? I will be very grateful.

Upvotes: 0

Views: 382

Answers (1)

Cuartero
Cuartero

Reputation: 455

I think the correct way to get the images is:

import requests

url = "https://github.com/PokeAPI/sprites/blob/ca5a7886c10753144e6fae3b69d45a4d42a449b4/sprites/pokemon/{id}.png?raw=true"
pokemon_id = "1"

response = requests.get(url.format(id=pokemon_id))

# Save the image
with open("pokemon.png", "wb") as f:
    f.write(response.content)

What saves an image of "Bulbasaur" in png format. Hope it helps!

Upvotes: 1

Related Questions