0
即时消息写一个脚本,从网站给出的IP,成功写了它,但现在我试图添加一些检查的IP本身,以便看到如果它下来,但它给我这个错误:Python IndentationError:预计在我的脚本上的缩进块
c:\Users\PC\Desktop>getip.py
File "C:\Users\PC\Desktop\getip.py", line 21
conn.connect((ip, port))
^
IndentationError: expected an indented block
下面是脚本:
# AUTHOR : G19
# Version : 1.0.0v
import time, socket, os, sys, string
print ("#####################################################")
print ("# SCRIPT : GETIP.PY #")
print ("# AUTHOR : G19 #")
print ("# VERSION: 1.0.0b #")
print ("#####################################################")
print ("")
host = raw_input('WEBSITE LINK : ')
ip = socket.gethostbyname(host)
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 80
def getip():
try:
conn.connect((ip, port))
conn.send("Sending packet confirmation")
except:
print ("")
print ("#####################################################")
print ("# STATUS : DOWN #")
print ("# IP: " + ip + " #")
print ("#####################################################")
print ("")
print ("")
print ("#####################################################")
print ("# STATUS : UP #")
print ("# IP: " + ip + " #")
print ("#####################################################")
print ("")
return
getip()
我猜你已经混合了制表符和空格 –
你的粘贴代码是可以的,但是python告诉你第21行的缩进存在问题。检查是否有相同的距离,并使用制表符或空格进行缩进。它有很大的帮助。 – wanderlust
问题是空格在崇高文本编辑器中正确显示,错误位于包含try旁边行的行: – user2090618