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. windows误人子弟啊2. php传对应的id值为什么传不了啊有木有大神会的看我下方截图3. python - linux 下用wsgifunc 运行web.py该如何修改代码4. python - oslo_config5. 关于mysql联合查询一对多的显示结果问题6. 实现bing搜索工具urlAPI提交7. 冒昧问一下,我这php代码哪里出错了???8. mysql优化 - MySQL如何为配置表建立索引?9. MySQL主键冲突时的更新操作和替换操作在功能上有什么差别(如图)10. 数据库 - Mysql的存储过程真的是个坑!求助下面的存储过程哪里错啦,实在是找不到哪里的问题了。
