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. node.js - 為什么用file協議打開的html可以連接websocket2. javascript - 為什么express,get的res.sendFile返回的是html純文本?3. CSS3中偽類選擇器的問題??求大神們解答4. node.js - 為什么npm安裝vue-cli會出現下面的錯誤??!!!?5. 微信支付 - python做微信企業付款出現CA證書錯誤6. 了解Java中的有限泛型。有什么意義?7. javascript - 用jquery實現表格行 置頂之后 如何跟后臺用ajax交互 在刷新之后仍保持當前位置?8. 前端 - css3傾斜帶來問題部分?9. javascript - Web微信聊天輸入框解決方案10. 網站在移動的環境下手機,pc打不開
