title: HTTP Basic Authentication not working with Python 3
body: <p>I am trying to access an intranet site with HTTP Basic Authentication enabled.</p>
  
  <p>Here's the code I'm using:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import urllib.request, base64, urllib.error
  
  request = urllib.request.Request(url)
  string = '%s:%s' % ('username','password')
  
  base64string = base64.standard_b64encode(string.encode('utf-8'))
  
  request.add_header("Authorization", "Basic %s" % base64string)
  try:
      u = urllib.request.urlopen(request)
  except urllib.error.HTTPError as e:
      print(e)
      print(e.headers)
  
  soup = BeautifulSoup(u.read(), 'html.parser')
  
  print(soup.prettify())
  </code></pre>
  
  <p>But it doesn't work and fails with <code>401 Authorization required.</code> I can't figure out why it's not working.</p>