Python错误:IndentationError:预期缩进块

时间:2015-05-19 16:15:57

标签: python

我已经创建了一个Python脚本来连接到telnet服务器,我收到了这个错误:

IndentationError: expected an indented block
File "./exploit_war.py", line 16
connect.connect((hostname, 21))

脚本的一部分是:

#!/usr/bin/python

import sys
import socket


 hostname = sys.argv[1]
 username = "whatever"


connect = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:

connect.connect((hostname, 21))


except:


print "[-] connection error"
response = connect.recv(2000)
print response
sys.exit(1)

有人能帮助我吗?

那将是非常好的..

由于

编辑:为什么这部分代码没有模拟输入密钥?:

connect.send("user %s\r\n" %username)
response = connect.recv(2000)
print response



connect.send("pass %s\r\n" %password)
response = connect.recv(2000)
print response

1 个答案:

答案 0 :(得分:4)

缩进就是Python中的一切:它定义了循环,函数,if语句的一部分......你应该通过一些基本的教程(https://docs.python.org/2/tutorial/)。对于您的代码,这应该有效:

angular.module('moduleName').directive('updateModelOnBlur', 
      ['$parse', function($parse) {
        return {
          restrict: 'A',
          require: 'ngModel',
          link: function (scope, elm, attrs) {
              elm.bind("blur", function (event) {
                scope.$apply(function () {
                  var model = $parse(attrs.ngModel);
                  model.assign( scope, elm.context.value );
                });
              });
          }
        };
      }]
    );

在您的代码中,行#!/usr/bin/python import sys import socket hostname = sys.argv[1] ## see how i changed the indentation of these two lines username = "whatever" connect = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: connect.connect((hostname, 21)) ## I also changed the indentation here except: print "[-] connection error" ## ... and here response = connect.recv(2000) # this line will raise an error if the connection attempt fails print response sys.exit(1) hostname = ...以空格开头,它们是缩进的。 Python期望以下行具有相同的缩进。