100
  File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)   gaierror: [Errno 11004]
getaddrinfo failed

Getting this error when launching the hello world sample from here:

http://bottlepy.org/docs/dev/

1
  • Is there a way to gracefully handle this error? I have a password reset form and it works fine if the EMAIL_HOST info is correct. But assuming that the e-mail server is down for some reason, how do I handle this case? It's all done under the covers by the django.contrib.auth() modules right now.
    – ravioli
    Commented Jul 19, 2018 at 2:07

6 Answers 6

96

It most likely means the hostname can't be resolved.

import socket
socket.getaddrinfo('localhost', 8080)

If it doesn't work there, it's not going to work in the Bottle example. You can try '127.0.0.1' instead of 'localhost' in case that's the problem.

1
  • 1
    Remmeber to put the quotes: socket.getaddrinfo('127.0.0.1', 8080) Commented Sep 29, 2014 at 14:20
18

The problem, in my case, was that some install at some point defined an environment variable http_proxy on my machine when I had no proxy.

Removing the http_proxy environment variable fixed the problem.

1
  • 1
    Notebook at work: everything great. Notebook at home: Failed. I set this environment variable a long time ago and forgot about it. I wonder why python's http library doesn't get proxy settings from the OS... BTW I was getting this error with easy_install Commented Nov 1, 2013 at 23:58
7

The problem in my case was that I needed to add environment variables for http_proxy and https_proxy.

E.g.,

http_proxy=http://your_proxy:your_port
https_proxy=https://your_proxy:your_port

To set these environment variables in Windows, see the answers to this question.

7

I spent some good hours fixing this but the solution turned out to be really simple. I had my ftp server address starting with ftp://. I removed it and the code started working.

FTP address before:

ftp_css_address = "ftp://science-xyz.xyz.xyz.int"

Changed it to:

ftp_css_address = "science-xyz.xyz.xyz.int"
2
  • Same for me, except I had to remove http:// , and change the class http.client.HTTPSConnection to http.client.HTTPConnection . I have only tried this with localhost:8000
    – gregn3
    Commented Apr 16, 2023 at 14:30
  • It's so weird that this case isn't handled in the gethostbyname function.
    – CrazyMan
    Commented Jun 6 at 20:05
5

Make sure you pass a proxy attribute in your command forexample - pip install --proxy=http://proxyhost:proxyport pixiedust

Use a proxy port which has direct connection (with / without password). Speak with your corporate IT administrator. Quick way is find out network settings used in eclipse which will have direct connection.

You will encouter this issue often if you work behind a corporate firewall. You will have to check your internet explorer - InternetOptions -LAN Connection - Settings

Uncheck - Use automatic configuration script Check - Use a proxy server for your LAN. Ensure you have given the right address and port.

Click Ok Come back to anaconda terminal and you can try install commands

4

May be this will help some one. I have my proxy setup in python script but keep getting the error mentioned in the question.

Below is the piece of block which will take my username and password as a constant in the beginning.

   if (use_proxy):
        proxy = req.ProxyHandler({'https': proxy_url})
        auth = req.HTTPBasicAuthHandler()
        opener = req.build_opener(proxy, auth, req.HTTPHandler)
        req.install_opener(opener)

If you are using corporate laptop and if you did not connect to Direct Access or office VPN then the above block will throw error. All you need to do is to connect to your org VPN and then execute your python script.

Thanks

Not the answer you're looking for? Browse other questions tagged or ask your own question.