#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Holland
    Posts
    4
    Rep Power
    0

    [Errno 11004] getaddrinfo failed


    Hi

    I'm trying to take my first steps in the Python language; I'm using python 2.7.2 on Windows 7.
    I bump into the following problem: I'm trying to open an url and the following error: [Errno 11004] getaddrinfo failed

    This is the code that's causing it:

    Code:
        import urllib, urllib2, httplib
    
        url = 'http://www.google.com'
        httplib.HTTPConnection.debuglevel = 1
    
        print "urllib"
    
        data = urllib.urlopen(url);
    urllib is printed to the output and then i get a stacktrace ending with:

    File "C:\Program Files\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    IOError: [Errno socket error] [Errno 11004] getaddrinfo failed
    I've searched for the problem and most people suggest that this is either a proxy problem or a dns problem.
    It's not a proxy problem; on the same machine i can open the webpage in my browser that does not have any proxy settings configured and also ping it from the command line.
    To rule out a DNS problem i tried the following:

    Code:
        url = 'http://173.194.65.94'
        data = urllib.urlopen(url);
    which gives a slightly different error:

    File "C:\Program Files\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    IOError: [Errno socket error] [Errno 11004] getaddrinfo failed
    I've also seen cases where people use the urllib2 class like this :
    Code:
        url = 'http://www.google.com'
        data = urllib2.urlopen(url);
    but this also gives me an error:

    File "C:\Program Files\Python27\lib\urllib2.py", line 1174, in do_open
    raise URLError(err)
    URLError: <urlopen error [Errno 11004] getaddrinfo failed>

    My first steps and i'm already stuck. I hope someone can point me in the right direction.

    btw, i tried the same thing in php (on the same machine)

    PHP Code:
        if ($handle fopen("http://www.google.com""r"))
        {
           echo 
    "opened succesfully";
           
    fclose($handle);   
        }
        else
        {
           echo 
    "error";
        } 

    And this works perfectly.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    430
    Rep Power
    66
    Originally Posted by themarty
    I'm trying to open an url and the following error: [Errno 11004] getaddrinfo failed

    This is the code that's causing it:

    Code:
        import urllib, urllib2, httplib
    
        url = 'http://www.google.com'
        httplib.HTTPConnection.debuglevel = 1
    
        print "urllib"
    
        data = urllib.urlopen(url);
    According to the docs, urllib.urlopen() has been deprecated in Python 2.6 in favour of urllib2.urlopen(). Both should still work however.

    I use mostly Python 3 which has neither, but when I tried urllib.urlopen() in Python 2.7 (under openSUSE 12.1) it most definitely worked:

    Code:
    Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib
    >>> urllib.urlopen('http://www.google.com/')
    <addinfourl at 3070328012L whose fp = <socket._fileobject object at 0xb70a5d2c>>
    So I have to suggest, too, that the problem is not in the Python code but in your computers network settings.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Holland
    Posts
    4
    Rep Power
    0
    Originally Posted by SuperOscar
    I use mostly Python 3 which has neither, but when I tried urllib.urlopen() in Python 2.7 (under openSUSE 12.1) it most definitely worked:

    Code:
    Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import urllib
    >>> urllib.urlopen('http://www.google.com/')
    <addinfourl at 3070328012L whose fp = <socket._fileobject object at 0xb70a5d2c>>
    So I have to suggest, too, that the problem is not in the Python code but in your computers network settings.
    Ok, but that still doesn't help me. As i showed, when i execute a similar command in PHP, it works. So my computer's network settings cannot be blamed 100%. Python's settings must have something to do with it as well. But since i'm such a rookie i have no idea where to start looking.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I ran the program of your first code block. It worked. This is the output. p.py is the file cut-n-paste from your post AFTER removing the leading indentations from each line. (A trivial task with emacs delete rectangle command.) I conclude, as did SuperOscar, your problem is elsewhere. And, since you didn't like that guess and since I see you posted indented code that ran, I'll guess that your problem lies in the part of your python program you have not shown us.

    Code:
    $ python p.py
    urllib
    send: 'GET / HTTP/1.0\r\nHost: www.google.com\r\nUser-Agent: Python-urllib/1.17\r\n\r\n'
    reply: 'HTTP/1.0 200 OK\r\n'
    header: Date: Tue, 27 Mar 2012 15:49:24 GMT
    header: Expires: -1
    header: Cache-Control: private, max-age=0
    header: Content-Type: text/html; charset=ISO-8859-1
    header: Set-Cookie: PREF=ID=f5450611736ba79e:FF=0:TM=1332863364:LM=1332863364:S=9rdWRj8OCjIfCLvi; expires=Thu, 27-Mar-2014 15:49:24 GMT; path=/; domain=.google.com
    header: Set-Cookie: NID=58=SSXmeSTiAMvi1G-_vMlILQBrgoFZ2HV5SZlheKL1ihTsFemyoB5Fv4ACja2L8rIGJA8jRuMIKJltGUpi8zwwKoan0sRoRZ2bdd9owQCPlAxNgXsdIfwpBqpmYZFJ4zIK; expires=Wed, 26-Sep-2012 15:49:24 GMT; path=/; domain=.google.com; HttpOnly
    header: P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
    header: Server: gws
    header: X-XSS-Protection: 1; mode=block
    header: X-Frame-Options: SAMEORIGIN
    Last edited by b49P23TIvg; March 27th, 2012 at 10:57 AM. Reason: Strike an extra line
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Holland
    Posts
    4
    Rep Power
    0
    The code suddenly started working after a reboot of my laptop. Later it stopped working again. I suspect that the problem occurs every time it is has been in hibernation.

IMN logo majestic logo threadwatch logo seochat tools logo