title: Python: urllib2.HTTPError: HTTP Error 401: Unauthorized
body: <p>I was trying to load a web page, but I ran into this problem. I do have the username and password, but I don't know how to use them in python code. I looked up on python tutorial, and this is what I wrote:</p>
  
  <pre><code>import urllib2
  
  password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
  username = 'user'
  password = 'pass'
  top_level_url = "www.something.com:80"
  password_mgr.add_password(None, top_level_url, username, password)
  handler = urllib2.HTTPBasicAuthHandler(password_mgr)
  opener = urllib2.build_opener(handler)
  opener.open('http://www.something.com/h/h.html')
  urllib2.install_opener(opener)
  response = urllib2.urlopen()
  page = response.read()
  print page
  </code></pre>
  
  <p>Anything wrong?</p>