[英]gaierror: [Errno 8] nodename nor servname provided, or not known
Hello I am new to python , I am writing a code which generates dns requests 您好,我是python的新手,我正在编写一个生成dns请求的代码
from socket import error as socket_error
import threading
from random import randint
from time import sleep
def task(number):
try :
HOST = Random_website.random_website().rstrip() # fetches url
PORT = 80 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print(str(number) +":"+HOST +"Connected")
except socket_error as serr:
if serr.errno != errno.ECONNREFUSED:
# Not the error we are looking for, re-raise
raise serr
thread_list = []
for i in range(1, 100):
t = threading.Thread(target=task, args=(i,))
thread_list.append(t)
for thread in thread_list:
thread.start()
Executing above code throws this error, can anyone help me out of this I am pulling out my hair from one day 执行以上代码会引发此错误,有人可以帮我解决这一问题吗?我有一天要拔头发
Thanks in advance 提前致谢
Like this: 像这样:
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("www.google.com",80))
>>> s.connect(("http://www.google.com",80))
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
s.connect(("http://www.google.com",80))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
gaierror: [Errno -2] Name or service not known
>>>
Socket not a HTTP
connection ! 套接字不是
HTTP
连接!
Remove HTTP://
tag before sending a request ! 发送请求之前,请删除
HTTP://
标记!
EDIT: 编辑:
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(("digan.net",80))
>>> s.connect(("digan.net/hahaha/hihihi/etc",80))
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
s.connect(("digan.net/hahaha/hihihi/etc",80))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
gaierror: [Errno -2] Name or service not known
>>>
Socket can't send request to additional path. 套接字无法将请求发送到其他路径。 Only talk with server !
只与服务器通话!
I got the same error message when a web proxy was "on", but the url pointed to a machine in the local network accessible without proxy. 当Web代理处于“打开”状态时,我得到了相同的错误消息,但是URL指向了没有代理即可访问的本地网络中的计算机。 Setting the web-proxy (http) to "off" fixed it for me.
将web-proxy(http)设置为“ off”对我来说已修复。
Hope this helps, Alex. 希望这会有所帮助,Alex。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.