Home python How to fix the error: socket.gaierror: GetAddrinfo Failed?

How to fix the error: socket.gaierror: [errno 11001] GetAddrinfo Failed?

Author

Date

Category

Error:

… for res in _socket.getaddrinfo (Host, Port, Family, Type, Proto, Flags):

Socket.Gaierror: [Errno 11001] GetAddrinfo Failed

During Handling Of The Above Exception, Another Exception OccurRED:

Python Code:

# - * - Coding: UTF-8 - * -
Import urllib.request
From LXml.html Import Parse
Website = 'http://allrecipes.com'
Url_page = 'http://allrecipes.com/recipes/110/appetizers-and-snacks/deviled-eggs/?page='
Start_page = 1.
END_PAGE = 5.
DEF Correct_str (s):
  RETURN S.NECODE ('UTF-8'). Decode ('ASCII', 'Ignore'). Strip ()
For i in Range (Start_Page, End_page + 1):
  URL = URL_PAGE + STR (I)
  HTML = URLLIB.Request.urlopen (URL)
  Page = PARSE (HTML) .Getroot ()
    # Skip video
  For Elem In Page.xpath ('// * [@ id = "Grid"] / article [NOT (Contains (@Class, "Video-Card"))] / a [1]):
    HREF = Website + Elem.get ('href')
    title = Correct_str (elem.find ('H3'). Text)
    Recipe_page = Parse (urllib.request.urlopen (href)). Getroot ()
    photo_url = recipe_page.xpath ('// IMG [@ class = "REC-Photo"]') [0] .get ('src')
    Print ('\ Nname: |', Title)
    Print ('Photo: |', photo_url)

Console – Results:

traceback (most recent call last):
Name: | Crab-Stuffed Deviled Eggs
 File "C: \ Users \ In \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", line 1240, in do_open
Photo: | http://images.media-allrecipes.com/userphotos/720x405/1091564.jpg
  H.REQUEST (REQ.GET_METHOD (), REQ.Selector, Req.data, Headers)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 1083, in Request
  Self._send_request (Method, URL, Body, Headers)
 File "C: \ Users \ In \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 1128, in _send_request
  Self.Endheaders (Body)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 1079, in Endheaders
  Self._send_output (Message_Body)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 911, in _send_output
  Self.send (MSG)
 File "C: \ Users \ In \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 854, in sen
  Self.Connect ()
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ http \ client.py", Line 826, in Connect
  (self.host, self.port), self.timeout, self.source_address)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ socket.py", Line 693, in Create_Connection
  For Res in Getaddrinfo (Host, Port, 0, Sock_stream):
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ socket.py", Line 732, in GetAddrinfo
  For res in _socket.getaddrinfo (Host, Port, Family, Type, Proto, Flags):
Socket.Gaierror: [ERRNO 11001] GetAddrinfo Failed
DURING HANDLING OF THE ABOVE EXCEPTION, ANOTHER EXCEPTION OCCURRED:
Traceback (MOST Recent Call Last):
 File "C: /Ussers/in/Dropbox/Parser/Test.py", Line 27, In & Lt; Module & GT;
  Recipe_page = Parse (urllib.request.urlopen (href)). Getroot ()
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", Line 162, In Urlopen
  Return Opener.open (URL, DATA, Timeout)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", Line 465, In Open
  Response = Self._Open (REQ, DATA)
 File "C: \ Users \ In \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", Line 483, in _Open
  '_Open', Req)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", Line 443, in _call_chain
  Result = Func (* Args)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py", Line 1268, in http_open
  Return Self.do_Open (http.client.httpConnection, Req)
 File "C: \ Users \ in \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ Urllib \ Request.py", line 1242, in do_open
  RAISE URLERROR (ERR)
urllib.error.urlerror: & lt; Urlopen Error [Errno 11001] GetAddrinfo Failed & GT; 
Process Finished With Exit Code 1

Answer 1, Authority 100%

GetAddrinfo Failed in the simplest case occurs if the URL provided cannot find the address. For example, “http: // google “, “Localhos”, “http://slkdfj.com

For a complete picture, you can read: https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx , http://man7.org/linux/man-pages/man3/getaddrinfo.3.html depending on the used OS

For example, what MSDN says about this error: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668%28v=vs.85%29.aspx#wsahost_not_found

no such host is known. The Name IS Not An Official Host Name Or Alias,
Or Cannot Be Found in the Database (S) Being Queried. This Error May Also
BE RETURNED FOR PROTOCOL AND SERVICE QUERIES, AND MEANS THAT THE SETCIFIED
Name Could Not Be Found in the Relevant Database.

In more complex cases, it all depends on network settings, Firewall.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions