title: how can I use python 3 to download a Teamcity artifact with basic auth
body: <p>I'm trying to download a zip artifact from teamcity using python 3 and i'm not having much luck.</p>
  
  <p>From the browser I would normally do this:
  <a href="http://USERNAME:PWD@SERVER/httpAuth/repository/downloadAll/dood_dad/latest.lastSuccessful" rel="nofollow">http://USERNAME:PWD@SERVER/httpAuth/repository/downloadAll/dood_dad/latest.lastSuccessful</a></p>
  
  <p>But if I try this with <strong>urllib.request.urlretrieve</strong> I get an exception about an invalid port - because It doesn't know about the username and password appended to the front of the url and is parsing after the ':' as a port - fair enough.</p>
  
  <p>So I guess I need to use teamcitys httpAuth stuff and use the url
  <a href="http://SERVERNAME/httpAuth/repository/downloadAll/dood_dad/latest.lastSuccessful" rel="nofollow">http://SERVERNAME/httpAuth/repository/downloadAll/dood_dad/latest.lastSuccessful</a></p>
  
  <p>When I try that I get a 404 Unauthorized which I expected because I need to supply the username and password. </p>
  
  <p>But I can't work out how.</p>
  
  <p>I've added this:</p>
  
  <pre><code>auth_handler = urllib.request.HTTPBasicAuthHandler()
  auth_handler.add_password(None,
                            uri=url_to_open,
                            user='userame',
                            passwd='password')
  opener = urllib.request.build_opener(auth_handler)
  urllib.request.install_opener(opener)
  local_filename, headers = urllib.request.urlretrieve(url)
  </code></pre>
  
  <p>But I'm still getting <strong>HTTP Error 401: Unauthorized</strong></p>
  
  <p>TIA.</p>