Solution to 403 Client Error: Forbidden for url with Python 3

Tari Yekorogha
2 min readMay 6, 2022

--

I tried all the solutions on StackOverflow till I found one that worked

Without further ado:

  1. use urllib instead of requests (Don’t worry it still works the same)
  2. use the import the Request() and urlopen() functions from urllib.request
a snippet of code that has written on it, “from urllib.request import Request, urlopen”.
Steps 1 and 2

3. Request the webpage with the Request() function. With the parameters url ( The webpage you want) and headers ( a dictionary of request headers but you should just set it yourself in the way, I did below 👇🏾)

4. Get the string data from the webpage with this code urlopen().read()

5. Use BeautifulSoap to parser your webpage and carry on with your work.

Final code snippet

Final code example

Conclusion

  • Have a Python question that you need an immediate answer to? DM me on Twitter. Or you could follow me for regular solutions to coding errors like this one. Link in bio
  • Need help on that crazy python assignment of yours. Don’t worry, “I’m here”
  • Hit me up on TeacherON. I’m teaching the first 1000 students for free. You’ll just have to pay me with an honest review
come on now, don’t be shy. I don’t bite.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tari Yekorogha
Tari Yekorogha

Written by Tari Yekorogha

A Christian boy with a laptop and a dream to break into the tech world.

Responses (2)

Write a response