Solution to 403 Client Error: Forbidden for url with Python 3
I tried all the solutions on StackOverflow till I found one that worked
Without further ado:
- use
urllib
instead ofrequests
(Don’t worry it still works the same) - use the import the
Request()
andurlopen()
functions fromurllib.request

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

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