close

[Solved] Python: urllib.error.HTTPError: HTTP Error 404: Not Found

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python: urllib.error.HTTPError: HTTP Error 404: Not Found in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python: urllib.error.HTTPError: HTTP Error 404: Not Found Error Occurs?

Today I get the following error Python: urllib.error.HTTPError: HTTP Error 404: Not Found in python.

How To Solve Python: urllib.error.HTTPError: HTTP Error 404: Not Found Error ?

  1. How To Solve Python: urllib.error.HTTPError: HTTP Error 404: Not Found Error ?

    To Solve Python: urllib.error.HTTPError: HTTP Error 404: Not Found Error I have exactly the same problem. The url that I want to get using urllib exists and is accessible using normal browser, but urllib is telling me 404.

  2. Python: urllib.error.HTTPError: HTTP Error 404: Not Found

    To Solve Python: urllib.error.HTTPError: HTTP Error 404: Not Found Error I have exactly the same problem. The url that I want to get using urllib exists and is accessible using normal browser, but urllib is telling me 404.

Solution 1

So apparently the default display number of questions per page is 50 so the range you defined in the loop goes out of the available number of pages with 50 questions per page. The range should be adapted to be within the number of total pages with 50 questions each.

This code will catch the 404 error which was the reason you got an error and ignore it just in case you go out of the range.

from urllib.request import urlopen

def find_bad_qn(a):
    url = "https://stackoverflow.com/questions?page=" + str(a) + "&sort=active"
    try:
        urlopen(url)
    except:
        pass

print("Please Wait.. it will take some time")
for i in range(298314,298346):
    find_bad_qn(i)

Solution 2

I have exactly the same problem. The url that I want to get using urllib exists and is accessible using normal browser, but urllib is telling me 404.

The solution for me is not use urllib:

import requests
requests.get(url)

This works for me.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read