python - 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")
解决方案
推荐阅读
- visual-studio-code - 如何在 VSCode 编辑器中为文件制作自己的编码
- android - 如何在沙盒模式下测试 InAppPurchase 订阅续订
- javascript - 如何从字符串中找到数组?
- javascript - 如何在 forEach 循环中等待 admin.auth().getUser() 方法?
- arduino - 将 Maxon SSI 编码器与 Arduinio Mega 连接以读取角位置
- patch - HAPI FHIR 尝试使用补丁
- c - 返回地址和堆栈布局
- react-native - webpack 不排除 react-native web 中的 node_modules
- c++ - 使用名称创建参数化构造函数对象
- ansible - Complex with_subelements construct