title: IDNA label empty or too long
body: <p>I'm trying to run a script of an online course and had to change the source code from python 2 to python 3 syntax. In this script, there is a download of an archive, which I already transformed into:</p>
  
  <pre><code>url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
  urllib.request.urlretrieve(url, filename="../enron_mail_20150507.tgz")
  </code></pre>
  
  <p>However, something seems to be wrong with the URL, since it gives me the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/encodings/idna.py", line 165, in encode
      raise UnicodeError("label empty or too long")
  UnicodeError: label empty or too long
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File "ud120_code_py35fork/tools/startup.py", line 37, in &lt;module&gt;
      data = urllib.request.urlretrieve("http://...")
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 187, in urlretrieve
      with contextlib.closing(urlopen(url, data)) as fp:
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 162, in urlopen
      return opener.open(url, data, timeout)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 465, in open
      response = self._open(req, data)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 483, in _open
      '_open', req)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 443, in _call_chain
      result = func(*args)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 1268, in http_open
      return self.do_open(http.client.HTTPConnection, req)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/urllib/request.py", line 1240, in do_open
      h.request(req.get_method(), req.selector, req.data, headers)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1083, in request
      self._send_request(method, url, body, headers)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1128, in _send_request
      self.endheaders(body)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 1079, in endheaders
      self._send_output(message_body)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 911, in _send_output
      self.send(msg)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 854, in send
      self.connect()
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/http/client.py", line 826, in connect
      (self.host,self.port), self.timeout, self.source_address)
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/socket.py", line 693, in create_connection
      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    File "/home/xiaolong/development/Python/udacity_intro_to_machine_learning/localpython/lib/python3.5/socket.py", line 732, in getaddrinfo
      for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
  </code></pre>
  
  <p>I already tried replacing the <code>~</code> and the <code>.</code> in the URL with <code>%7E</code> and <code>%2E</code>, but that didn't help at all.</p>
  
  <p>What's wrong with the URL and how can I fix this?</p>
  
  <ul>
  <li>exact python version: 3.5.1</li>
  </ul>