2016-01-02 61 views
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() 
+3

我猜你已经混合了制表符和空格 –

+0

你的粘贴代码是可以的,但是python告诉你第21行的缩进存在问题。检查是否有相同的距离,并使用制表符或空格进行缩进。它有很大的帮助。 – wanderlust

+0

问题是空格在崇高文本编辑器中正确显示,错误位于包含try旁边行的行: – user2090618

回答

1

你混合制表符和空格。 try:行缩进一个制表符,下一行包含空格;我的编辑器显示的选项卡的线,空格为点,当被选择时:

tab circled

Python的扩展标签来空格,因此到Python,有线之间没有差别。

不要混合标签和空格。配置您的编辑器始终将缩进展开为空格,并用空格替换所有现有的标签。 PEP 8(python styleguide)recommends spaces over tabsGoogle Python styleguide也一样。

相关问题