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. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?2. javascript - echart+百度地图3. web - Rails3使用form_for时出现undefined method `*_path’错误。4. css - autoprefixer没有添加web-kit前缀5. 无效的配置对象已使用与API模式不匹配的配置对象初始化了Webpack6. javascript 开发百度地图7. nginx - 关于vue项目部署到ngnix后出现的问题8. angular.js - 百度爬虫如何处理“#”符号?9. nosql - mongodb 多组数据不固定字段查询问题 [百度党请绕道]10. css3 - 请问,如何通过CSS实现高度height随宽度width变化而变化,保持长宽比例不变,宽度是根据父元素宽度变化的?
