0

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)
4
  • What do you want to do? Commented May 20, 2020 at 16:48
  • Just use beautifulsoup library to fetch the API data from the link. Commented May 20, 2020 at 16:48
  • I want to get the data from that url and print the object to the console. Commented May 20, 2020 at 16:49
  • use beautiful soup library to fetch the data Commented May 20, 2020 at 16:49

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

1 Comment

@ZeroSevenTen The requests module is a third party library, but it has become the standard (and best) way to make requests in Python. If you are able to install it in your environment, I would go with this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.