URLError: <urlopen error [Errno 11001] getaddrinfo failed>

Chris Angelico rosuav at gmail.com
Sat Feb 12 15:25:36 EST 2022


On Sun, 13 Feb 2022 at 07:17, Shaozhong SHI <shishaozhong at gmail.com> wrote:
>
> The following is used in a loop to get response code for each url.
>
> print (urllib.request.urlopen(url).getcode())
>
> However, error message says: URLError: <urlopen error [Errno 11001]
> getaddrinfo failed>
>
> Python 3.6.5 is being used to test whether url is live or not.
>
> Can anyone shed light on this?
>

What that's saying is that it couldn't look up the domain name to get
the corresponding address. Most likely, that means you either don't
have DNS available, or the DNS server said that it couldn't find that
server. (Whether that's true or not. It's always possible for the DNS
server to be wrong.) So, if you can fairly safely assume that you have
a fully-functioning internet connection (for instance, if other URLs
can be fetched successfully), the most reasonable interpretation of
this is that the URL is, in some way, broken.

I suspect that errno 11001 is a Winsock error, in which case it would
mean "Host not found". On my Linux system, I get a chained exception
that says "Name or service not found". Most likely, you can find this
information further up in the traceback.

ChrisA


More information about the Python-list mailing list