python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)
问题描述
# -*- 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()
问题解答
回答1:提示说tryMsgcode()方法接受2个参数但是你一个都没传
相关文章:
1. linux - Ubuntu下编译Vim8(+python)无数次编译失败2. javascript - 弹出一个子窗口,操作之后关闭,主窗口会得到相应的响应,例如网站的某些登录界面,django后台的管理等,这是怎么实现的呢?3. list - python 求助4. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题5. javascript - 函数设置参数默认值的问题6. extra没有加载出来7. javascript - react,获取radio的值出错8. 环境搭建 - anaconda 创建python2.7环境中打开编译器确是3.6版本9. mysql replace 死锁10. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?
