title: Python 3 variable in request causing 404?
body: <p>I've got two lists, one a list of dates the other a list of hours and I'm scanning a website looking for content.  </p>
  
  <pre><code>date = ['1','2','3']
  hour = ['1','2','3']
  </code></pre>
  
  <p>I've written the following <code>while</code> / <code>for</code> to loop through the dates and hours and open all the combinations:   </p>
  
  <pre><code>datetotry = 0  
  while (datetotry &lt; len(date)):
      for i in range(len(hour)):              
          print ('https://www.website.org/backups/backup_2004-09-'+date[datetotry]+'_'+hour[i]+".sql")
          html = opener.open('https://www.website.org/backups/backup_2004-09-'+date[datetotry]+'_'+hour[i]+'.sql').read()
  datetotry += 1
  </code></pre>
  
  <p>When the console prints the url it looks okay with the variables being replaced with the numbers from the list. </p>
  
  <p>But its possibly not replacing the variables in the actual url request. </p>
  
  <p>The code was stopping due to a 404 error but I think I handled that with the info I found here:</p>
  
  <p><a href="https://docs.python.org/3/howto/urllib2.html#wrapping-it-up" rel="nofollow">https://docs.python.org/3/howto/urllib2.html#wrapping-it-up</a></p>
  
  <p>The first part of the 404 error was showing the    </p>
  
  <pre><code>date[datetotry]+'_'+hour[i]+
  </code></pre>
  
  <p>section, instead of the items from the list like when its printing to console.  </p>
  
  <p>Does this mean I have to do something like <code>urllib.parse.urlencode</code> to actually replace the variables?   </p>
  
  <p>I imported the libraries mentioned in the article and changed code to:  </p>
  
  <pre><code> from urllib.error import URLError, HTTPError
   from urllib.request import Request, urlopen
  
  while (datetotry &lt; len(date)):
  for I in range(len(hour)):              
      HTML = Request('https://www.website.org/backups/backup_2004-09-'+date[datetotry]+'_'+hour[i]+'.sql')
      try:
          response = urlopen(html)
      except URLError as e:
          print('The server couldn\'t fulfill the request.')
          print('Error code: ', e.code)
      except URLError as e:
          print('We failed to reach a server.')
          print('Reason: ', e.reason)
      else:
  </code></pre>
  
  <p>So the code actually runs, not stopping due to 404 being returned. What is the best way to see what its actually requesting and do I have to do some kind of encoding? New to programming especially Python 3.  </p>