ZeroSevenTen
ZeroSevenTen

Reputation: 1394

Python: Can't fetch data from API

This is all my code. It's giving me a 403 forbidden error, even though if I type the same URL into google, I get the data.

import urllib.request, json

with urllib.request.urlopen('https://pokeapi.co/api/v2/pokemon/1') as url:
    data = json.loads(url.read().decode())
    print(data)

Upvotes: 0

Views: 297

Answers (1)

jv95
jv95

Reputation: 691

if I use the requests module, it works

import requests  
response = requests.get('https://pokeapi.co/api/v2/pokemon/')
for i in response: print(i)

Upvotes: 4

Related Questions