您的位置:首页技术文章
文章详情页

python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)

【字号: 日期:2022-08-15 08:22:21浏览:63作者:猪猪

问题描述

# -*- coding: utf-8 -*-import urllib2import urllibimport httplibimport threadingimport random# lock = threading.Lock()def tryMsgcode(MsgCode): # print user,password global headers global outFile conn = httplib.HTTPConnection('localhost') if len(MsgCode) < 3: # 限制字典,排除字典中的无用数据return # 主动退出线程 else:# lock.acquire() # 多线程操作文件,提前加锁,用后释放# line = inFile.readline()# lock.release()conn.request(method='GET', url='/test.aspx?UserName=test&Password=123456&MsgCode=%s&random=0.790281244798%s' % (MsgCode, random.randint(1111, 9999)))responseText = conn.getresponse().read().decode(’utf8’) # 网页编码# print responseText # 第一次可以打印看看是否解析if not responseText.find(u’3’) > 0: print ’Sueessed:’, ExCode outFile.write(’MsgCode:’ + MsgCode + ’n’)else: print ’Error:’ + MsgCode + ’n’ returnoutFile = open(’Msgcode-sussessed.txt’, ’w’)if __name__ == ’__main__’: tsk = [] # 创建线程池 with open(r’msg.dic’, ’r’) as MsgCodeDic: # 使用with as 来打开文件,不需自己关闭文件,因为他会自己在合适的时候自已关闭(类似C# 中的using(...){}接口) for Code in MsgCodeDic.readlines(): t = threading.Thread(target=tryMsgcode(Code), args=Code) t.daemon = False # 设置不进行进程守护 tsk.append(t) # t.start() MsgCodeDic.seek(0)# 记住这里要将文件重新移到文件首,不然就会出现只执行外层循环的第一条,因为内层在# 迭代之后(readlines()是迭代器的形式,迭代一次后文件指针就指到文件尾了,迭代器# 也是end了)第二次就没有password 在 fPass中,也就是说 for password in fPass.readlines():# 为空,所以这里的内层循环就不会被执行了,因此也就是迭代器清零的问题(C ++ itertor 常有)# join()无参数就是完全阻塞主线程,等待线程执行完 有参数就是说,# 在主线程等待一秒后就不阻塞线程了,继续执行主线程,这里的意思是一秒钟开一个线程# 不能再thread start之前调用join(), 因为join() 是线程运行时调度 for t in tsk:t.start()t.join(1) print 'All thread OK,maybe not ' outFile.close()

python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)

问题解答

回答1:

提示说tryMsgcode()方法接受2个参数但是你一个都没传

标签: Python 编程
相关文章: