Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:55:06+00:00 2026-05-17T21:55:06+00:00

A week or so ago someone on StackOverflow asked why their Python code for

  • 0

A week or so ago someone on StackOverflow asked 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!).

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:

>>> from socket import *
>>> s = socket(AF_INET6, SOCK_STREAM)
>>> s.connect(('fe80::21f:5bff:fe3f:1b36%en0', 2001))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in connect
socket.error: [Errno 65] No route to host

The following code, on the other hand, DOES work (with or without the %en0 suffix):

>>> from socket import *
>>> s = socket(AF_INET6, SOCK_STREAM)
>>> s.connect(('fe80::21f:5bff:fe3f:1b36%en0', 2001, 0, 6))
>>> 

… 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.

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?

FWIW, I am testing with Python 2.6.1 under MacOS/X 10.6.4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:55:07+00:00Added an answer on May 17, 2026 at 9:55 pm

    This is the correct way to do an ipv6 connection:

    >>> addrinfo = getaddrinfo('fe80::225:ff:fecd:5aa0%en0', 2001, AF_INET6, SOCK_STREAM)
    >>> addrinfo
    [(30, 1, 6, '', ('fe80::225:ff:fecd:5aa0%en0', 2001, 0, 4))]
    >>> (family, socktype, proto, canonname, sockaddr) = addrinfo[0]
    >>> s = socket(family, socktype, proto)
    >>> s.connect(sockaddr)
    

    getaddrinfo() will return the correct numerical scope and flow information for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was kind of scratching my head at this a week ago, and now
Open up a Rails console and enter this: 2.weeks.ago.between? 2.weeks.ago, 1.week.ago Did it give
Ok, I had a simple layout problem a week or two ago. Namely sections
Last week we released Omniture's analytics code onto a large volume of web sites
Last week I implemented a date validation in our front end, a combination of
For customer service week this year, I have the privileged task of creating a
Given a week number, e.g. date -u +%W , how do you calculate the
Earlier this week I ask a question about filtering out duplicate values in sequence
Given a week-day (1-7), how can I calculate what that week-day's last date was?
The last week on the ACM ICPC Mexico competition, I missed a return 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.