简体   繁体   English

(Python)socket.gaierror:[Errno 11001] getaddrinfo失败

[英](Python) socket.gaierror: [Errno 11001] getaddrinfo failed

I'm not sure whats wrong with this code I keep getting that socket.gaierror error ;\\ . 我不确定这段代码有什么问题我一直得到socket.gaierror错误; \\。

import sys
import socket
import random

filename = "whoiservers.txt"

server_name = random.choice(list(open(filename)))

print "connecting to %s..." % server_name

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server_name, 43))
s.send(sys.argv[1] + "\r\n")
response = ''
while True:
    d = s.recv(4096)
    response += d
    if d == '':
        break
s.close()
print
print response


    s.connect((server_name, 43))
  File "<string>", line 1, in connect
socket.gaierror: [Errno 11001] getaddrinfo failed

Update: 更新:

After adding server_name = random.choice(list(open(filename)))[:-1] I dont get that socket.gaierror anymore but I get: 添加server_name = random.choice(list(open(filename)))[:-1]我再也没有得到socket.gaierror但是我得到了:

socket.error: [Errno 10060] A connection attempt failed because the connected pa rty did not properly respond after a period of time, or established connection f ailed because connected host has failed to respond socket.error:[Errno 10060]连接尝试失败,因为连接的文件在一段时间后没有正确响应,或者由于连接的主机无法响应而建立的连接失败

I think the problem is a newline at the end of server_name . 我认为问题是server_name末尾的换行符。

If the format of your file whoiservers.txt is one hostname on each line then you need to strip the newline at the end of the hostname before passing it to s.connect() 如果您的文件whoiservers.txt的格式是每行上的一个主机名,那么您需要在主机名末尾删除换行符,然后再将其传递给s.connect()

So, for example, change the open line to: 因此,例如,将开放行更改为:

server_name = random.choice(list(open(filename)))[:-1]

Perhaps you have a firewall in between you and these servers that is blocking the request? 也许您和这些阻止请求的服务器之间有防火墙? The last error you posted leads one to believe that it cannot connect to the server at all... 您发布的最后一个错误导致人们相信它根本无法连接到服务器...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 socket.gaierror:[Errno 11001] getaddrinfo 失败 - socket.gaierror: [Errno 11001] getaddrinfo failed Scapy导入错误&#39;socket.gaierror:[Errno 11001] getaddrinfo失败&#39; - Scapy import error 'socket.gaierror: [Errno 11001] getaddrinfo failed' 错误:- socket.gaierror:[Errno 11001] getaddrinfo 在获取请求中失败 - Error :- socket.gaierror: [Errno 11001] getaddrinfo failed in get request 如何解决:socket.gaierror: [Errno 11001] getaddrinfo failed - How to solve: socket.gaierror: [Errno 11001] getaddrinfo failed socket.gaierror: [Errno 11001] getaddrinfo 在 django 中失败 - socket.gaierror: [Errno 11001] getaddrinfo failed in django 当我在 python 中使用套接字模块时,我收到此错误:'socket.gaierror: [Errno 11001] getaddrinfo failed' - I get this error:' socket.gaierror: [Errno 11001] getaddrinfo failed' when I use the socket module in python socket.gaierror: [Errno 11001] getaddrinfo failed" in python,同时使用简单的自定义 web 浏览器 - socket.gaierror: [Errno 11001] getaddrinfo failed" in python, while using a simple custom web browser 处理获取 socket.gaierror 的错误:[Errno 11001] getaddrinfo 在 Python 中使用 pyopenssl 失败 - Handling error for Getting a socket.gaierror: [Errno 11001] getaddrinfo failed using pyopenssl in Python getaddrinfo失败,出现socket.gaierror [11001](python)(mqtt) - getaddrinfo failed with socket.gaierror[11001] (python) (mqtt) socket.gaierror:[Errno 11003] getaddrinfo失败 - socket.gaierror: [Errno 11003] getaddrinfo failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM