[英](Python) gaierror: [Errno 11004] getaddrinfo failed
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失敗”,謝謝您的幫助。
錯誤:
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
我的猜測是因為您使用的主機名帶有換行符。 在我編寫此答案時,您的代碼顯示:
def Info():
targetip = socket.gethostbyname_ex(text1.get("1.0", END))
text.insert(END, targetip)
使用索引END
您會獲得由文本小部件添加的額外換行符。 您需要刪除它或使用索引"end-1c"
。
為什么在查找主機名之前將CRLF( \\r\\n
)添加到主機名?
如果刪除不能解決問題,請打印出要傳遞給gethostbyname的確切文本,以確保它是有效的主機名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.