2016-02-12 85 views
-1

我的代码是在这里网站IP地址的打印机,蟒蛇不工作

ip=int(input("What website do u need the ip address from?")) 
ipad=socket.gethostbyname(ip) 
print("Thats websites ip is",ipad) 
wait=input("Press enter to exit") 
os.system('cls') 

那么这将返回一个错误 ValueError: invalid literal for int() with base 10: 'www.google.com'

回答

0

你不能投字符串'www.google.com'int

此外,socket.gethostbyname(hostname)翻译一主机名称为IPv4地址格式,所以其输入不是int,而是string

1

您有:

ip=int(input("What website do u need the ip address from?")) 

所以,由于某种原因,你想你的输入转换为整数,然后分配到一个名为“IP”变量。如果你输入一个整数,那么你的错误将消失 - 当然,如果你想让人们输入webite主机名,这是没有用的。

每当你遇到这样的错误时,停下来仔细地仔细阅读错误信息,并检查你的代码。不是你写的认为是的代码,但是屏幕上显示的是什么。