socket.gaierror: [Errno 11001] 连接到 URL python 时 getaddrinfo 失败

时间:2021-03-25 18:03:40

标签: python sockets

我想检查一个特定的套接字是打开还是关闭了一个 url,但是每当我尝试连接它时都会给我这个错误:socket.gaierror: [Errno 11001] getaddrinfo failed

我不明白为什么会这样。

def checkSockets(url):
    a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    location = (url, 80)
    res_check = a_socket.connect_ex(location)
    if res_check == 0:
        print(0)
    else:
        print(1)
    a_socket.close()

checkSockets("https://www.youtube.com")

0 个答案:

没有答案