socket.gaierror: [Errno 11001] getaddrinfo failed in Python

Dung Do Tien Jan 20 2021 632

I'm running my code in Python Ver3.9(Window10) and get the error status: socket.gaierror: [Errno 11001] getaddrinfo failed, here my code:

#!/usr/bin/python
import socket

HOST = "https://google.com"
PORT = 80
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.connect((HOST,PORT))

print("REAL_HOST: ",HOST)
print(server)

In my program, I have a URL to call, I need a solution to solve it thoroughly on my computer and others too. Help me, many tks guys! 

Have 1 answer(s) found.
  • M

    Milan cubes Jan 20 2021

    Okayhere my solutions :

    Step 1: Check The correct Url again u want to use In Module Socket or Socks.

    Step 2: If you see "https: //" or "http: //" in Url, remove it from the URL.

    Below is my code for having a valid Url for the socket Module(Useful for all Url):

    #!/usr/bin/python
    import socket
    
    HOST = "dabep.net"
    REAL_HOST = HOST.replace("http://", "").replace("https://", "").split("/")[0].split(":")[0]
    PORT = 80
    server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    server.connect((REAL_HOST,PORT))
    
    print("REAL_HOST: ",REAL_HOST)
    print(server)

    I hope my solution useful for you, If you still have questions, please comment below for my support:)))

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close