(Python) gaierror: [Errno 11004] getaddrinfo 失败 [英] (Python) gaierror: [Errno 11004] getaddrinfo failed
本文介绍了(Python) gaierror: [Errno 11004] getaddrinfo 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
from Tkinter import *
import tkMessageBox, socket
root = Tk()
root.title("pynet v1.0")
root.config(bg='black')
root.resizable(0,0)
text = Text()
text1 = Text()
text1.config(width=15, height=1)
text1.config(bg="white", fg="red")
text1.pack()
def Info():
targetip = socket.gethostbyname_ex(text1.get("1.0", END))
text.insert(END, targetip)
b = Button(root, text="Enter", width=10, height=2, command=Info)
b.config(fg="black", bg="red")
b.pack(side=TOP, padx=5)
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=25, height=5, bg="white", fg="red")
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)
root.mainloop()
我正在尝试检索网站的 IP 地址,但在第 18 行中不断收到此错误,gaierror: [Errno 11004] getaddrinfo failed",我们将不胜感激,谢谢.
I'm trying to retrieve the IP Address of a website, but I keep getting this error, "gaierror: [Errno 11004] getaddrinfo failed" in line 18, your help will be appreciated, Thanks.
错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\Rabia\Desktop\gethostinfo.py", line 18, in Info
targetip = socket.gethostbyname_ex(text1.get("1.0", END))
gaierror: [Errno 11004] getaddrinfo failed
推荐答案
我的猜测是因为您使用的主机名带有尾随换行符.在我写这个答案的时候,你的代码显示:
My guess is because you are using a hostname that has a trailing newline. At the time I write this answer, your code shows:
def Info():
targetip = socket.gethostbyname_ex(text1.get("1.0", END))
text.insert(END, targetip)
当您使用索引 END
时,您将获得由文本小部件添加的额外换行符.您需要将其剥离或使用索引 "end-1c"
.
When you use the index END
you get the extra newline that is added by the text widget. You need to strip that off or use the index "end-1c"
.
这篇关于(Python) gaierror: [Errno 11004] getaddrinfo 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文