title: Why doesn't a %en0 suffix work to connect a link-local IPv6 TCP socket in Python?
body: <p>A week or so ago someone on StackOverflow <a href="https://stackoverflow.com/questions/3895570/why-the-connect-failed-for-ipv6-at-python">asked</a> why their Python code for connecting to an IPv6 link-local address wasn't working, and I replied that since it was a link-local address they needed to add a %en0 (or whatever the desired local-interface-name is) suffix to their target IP address.  I thought I knew what I was talking about, so I didn't actually test my suggestion before answering (shame on me!).</p>
  
  <p>Today I went to use that same technique for myself, only to find that it doesn't seem to work.  :^(  That is, this code does not work:</p>
  
  <pre><code>&gt;&gt;&gt; from socket import *
  &gt;&gt;&gt; s = socket(AF_INET6, SOCK_STREAM)
  &gt;&gt;&gt; s.connect(('fe80::21f:5bff:fe3f:1b36%en0', 2001))
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;string&gt;", line 1, in connect
  socket.error: [Errno 65] No route to host
  </code></pre>
  
  <p>The following code, on the other hand, DOES work (with or without the %en0 suffix):</p>
  
  <pre><code>&gt;&gt;&gt; from socket import *
  &gt;&gt;&gt; s = socket(AF_INET6, SOCK_STREAM)
  &gt;&gt;&gt; s.connect(('fe80::21f:5bff:fe3f:1b36%en0', 2001, 0, 6))
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>... but I don't like doing it that way, because in order to figure out which scope ID integer to supply for the last argument, I have to execute a bunch of not-very-portable code to iterate over the local interfaces list, find the interface named 'en0', and extract its scope ID, which is more complexity overhead than I'd like to have.</p>
  
  <p>Given that connect() is accepting the %en0 suffix to the IP address, why isn't it actually using it as expected to determine the scope ID?</p>
  
  <p>FWIW, I am testing with Python 2.6.1 under MacOS/X 10.6.4.</p>