我收到以下错误,无法解决问题

时间:2014-03-06 11:10:52

标签: python

我正在学习Python并开始整理下面的代码。我试图让fread功能正常工作,但我收到了错误。

我已经尝试了几种方法来解决它但当然如果我不知道导致它的原因我永远不会解决它。

我希望有人可以帮助我。

错误

unknown@ubuntu:~$ ./attack.py -f wordfile.txt
Traceback (most recent call last):
  File "./attack.py", line 63, in <module>
    print fread(list)
  File "./attack.py", line 20, in fread
    flist = open(list).readlines()
TypeError: coercing to Unicode: need string or buffer, type found`

CODE

#!/usr/bin/python


import sys, getopt, socket, fileinput, traceback
import dns.query, dns.message, dns.name, adns
from Queue import Queue
from threading import Thread


def usage():
    print "-h --help: help\n"
    print "-f --file: File to read bruteforce domain list from.\n"
    print "-p --proxy: Proxy address and port. e.g http://192.168.1.64:8080\n"
    print "-d --domain: Domain to bruteforce.\n"
    print "-t --thread: Thread count.\n"
    print "-e: Turn debug on.\n"
    sys.exit()

def fread(list, *args):
   flist = open(list).readlines()
   return flist

def addcheck(fcontent):
   data =[]
   c=adns.init()
   for sub in file:
     SubDomain = fcontent + domain
     data[SubDomain] = c.synchronous(SubDomain, adns.rr.A)
   return data


def main(argv):
  list = None
  proxy = None
  domain = None
  FILE= None
  try:
     opts, argv =getopt.getopt(argv, "h:f:p:d:t:e",["help", "file=", "proxy=", "domain=", "thread="])

  except getopt.GetoptError as err:
    print str(err)
    usage()
    sys.exit(2)

  for opt, arg in opts:
      if opt in ("-h", "--help"):
          usage()
          sys.exit()
      elif opt in ("-f", "--file"):
          list = arg
      elif opt in ("-p", "--proxy"):
          proxy = arg
      elif opt in ("-d", "--domain"):
          domain = arg
      elif opt in ("-t", "--thread"):
          thread = arg
      elif opt in '-e':
          global _debug

print fread(list)
if __name__ == "__main__":
   main(sys.argv[1:])

1 个答案:

答案 0 :(得分:1)

您在这里传递list类型对象:

print fread(list)

这是main函数的外部,因此list仍然绑定到内置类型。

您可能意味着该行成为main()函数的一部分。如果是这样,请进一步缩进以匹配函数中的其余代码。

但是,您确实不应该使用list作为变量名。已有内置type of that name;因此,您的缩进错误会给您一个令人困惑的异常消息。也许fnamefilename可能是更好的选择。