Skip to content

Commit d1c0639

Browse files
committed
Merge pull request RaspberryPiFoundation#43 from VitalBear/master
fixed potential security issue: eval is unsafe, use ast.literal_eval instead
2 parents 1289d61 + a5c005a commit d1c0639

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

en-GB/lessons/Pokedex/Project Resources/pokeapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import io
22
import urllib.request
33
from urllib.request import urlopen
4+
import ast
45
from PIL import Image, ImageTk
56

67
#function to get the data for a pokemon
78
def getPokemonData(num):
89
data = urllib.request.urlopen("http://pokeapi.co/api/v1/pokemon/"+str(num)).read()
9-
pokemonDict = eval(data)
10+
pokemonDict = ast.literal_eval(data.decode(encoding='UTF-8'))
1011
return pokemonDict
1112

1213
#function to get the image for a pokemon
1314
def getPokemonImage(num):
1415
data = urllib.request.urlopen("http://pokeapi.co/api/v1/sprite/"+str(num)).read()
15-
spriteDict = eval(data)
16+
spriteDict = ast.literal_eval(data.decode(encoding='UTF-8'))
1617
imgURL = "http://pokeapi.co" + spriteDict["image"]
1718
image_bytes = urlopen(imgURL).read()
1819
data_stream = io.BytesIO(image_bytes)

0 commit comments

Comments
 (0)