I am trying to acces data from the pokemon api and get some information from there. First you need to put in a number (only option 1 works right now). Then the pokemon name/number and the url is formed. but I get a lot of errors when
data = json.loads(THEURL)
print(data['forms']['name'])
What am I doing wrong?
#importception
import requests
import json
#import poke api
api_url = 'http://pokeapi.co/api/v2/'
#welke database
def databaseaanvragen():
print('Welke database wilt u aanvragen?')
print('Hallo), wat wilt u doen?')
print('1) Pokemons')
print('2) Locations')
print('3) Moves')
keuze = input('Voer hier het nummer in: ')
if(keuze.isdigit()):
keuze = int(keuze)
if keuze == 1:
poke_naam = input('Voer de naam of het nummer van de Pokemon in: ')
poke_value = 'pokemon/' + poke_naam
return poke_value
#database url en data aanvragen
aangevraagd = api_url + databaseaanvragen()
data = json.loads(aangevraagd)
print(data['forms']['name'])
json.loadsexpects a string containing the JSON to be decoded, not a URL.json.loadinstead expects an open file pointer. In short: thejsonmodule will not do an actual HTTP request to get the JSON document, that's not its job; you'll need to do that yourself.