首页 > 解决方案 > socket.gaierror: [Errno 11001] getaddrinfo 连接到 URL python 时失败

问题描述

我想检查一个特定的套接字是打开还是关闭一个 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")

标签: pythonsockets

解决方案


推荐阅读