title: Python: urllib.error.HTTPError: HTTP Error 404: Not Found
body: <p>I wrote a script to find spelling mistakes in SO questions' titles.
  I used it for about a month.This was working fine. </p>
  
  <p>But now, when I try to run it, I am getting this.</p>
  
  <pre><code>Traceback (most recent call last):
    File "copyeditor.py", line 32, in &lt;module&gt;
      find_bad_qn(i)
    File "copyeditor.py", line 15, in find_bad_qn
      html = urlopen(url)
    File "/usr/lib/python3.4/urllib/request.py", line 161, in urlopen
      return opener.open(url, data, timeout)
    File "/usr/lib/python3.4/urllib/request.py", line 469, in open
      response = meth(req, response)
    File "/usr/lib/python3.4/urllib/request.py", line 579, in http_response
      'http', request, response, code, msg, hdrs)
    File "/usr/lib/python3.4/urllib/request.py", line 507, in error
      return self._call_chain(*args)
    File "/usr/lib/python3.4/urllib/request.py", line 441, in _call_chain
      result = func(*args)
    File "/usr/lib/python3.4/urllib/request.py", line 587, in http_error_default
      raise HTTPError(req.full_url, code, msg, hdrs, fp)
  urllib.error.HTTPError: HTTP Error 404: Not Found
  </code></pre>
  
  <p>This is my code</p>
  
  <pre><code>import json
  from urllib.request import urlopen
  from bs4 import BeautifulSoup
  from enchant import DictWithPWL
  from enchant.checker import SpellChecker
  
  my_dict = DictWithPWL("en_US", pwl="terms.dict")
  chkr = SpellChecker(lang=my_dict)
  result = []
  
  
  def find_bad_qn(a):
      url = "https://stackoverflow.com/questions?page=" + str(a) + "&amp;sort=active"
      html = urlopen(url)
      bsObj = BeautifulSoup(html, "html5lib")
      que = bsObj.find_all("div", class_="question-summary")
      for div in que:
          link = div.a.get('href')
          name = div.a.text
          chkr.set_text(name.lower())
          list1 = []
          for err in chkr:
              list1.append(chkr.word)
          if (len(list1) &gt; 1):
              str1 = ' '.join(list1)
              result.append({'link': link, 'name': name, 'words': str1})
  
  
  print("Please Wait.. it will take some time")
  for i in range(298314,298346):
      find_bad_qn(i)
  for qn in result:
      qn['link'] = "https://stackoverflow.com" + qn['link']
  for qn in result:
      print(qn['link'], " Error Words:", qn['words'])
      url = qn['link']
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is the url causing the problem.Even though this url exists.</p>
  
  <p><a href="https://stackoverflow.com/questions?page=298314&amp;sort=active">https://stackoverflow.com/questions?page=298314&amp;sort=active</a></p>
  
  <p>I tried changing the range to some lower values. It works fine now.</p>
  
  <p>Why this happened with above url?</p>