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: # 限制字典,排除字典中的無用數(shù)據(jù)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’) # 網(wǎng)頁編碼# 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 = [] # 創(chuàng)建線程池 with open(r’msg.dic’, ’r’) as MsgCodeDic: # 使用with as 來打開文件,不需自己關(guān)閉文件,因?yàn)樗麜约涸诤线m的時候自已關(guān)閉(類似C# 中的using(...){}接口) for Code in MsgCodeDic.readlines(): t = threading.Thread(target=tryMsgcode(Code), args=Code) t.daemon = False # 設(shè)置不進(jìn)行進(jìn)程守護(hù) tsk.append(t) # t.start() MsgCodeDic.seek(0)# 記住這里要將文件重新移到文件首,不然就會出現(xiàn)只執(zhí)行外層循環(huán)的第一條,因?yàn)閮?nèi)層在# 迭代之后(readlines()是迭代器的形式,迭代一次后文件指針就指到文件尾了,迭代器# 也是end了)第二次就沒有password 在 fPass中,也就是說 for password in fPass.readlines():# 為空,所以這里的內(nèi)層循環(huán)就不會被執(zhí)行了,因此也就是迭代器清零的問題(C ++ itertor 常有)# join()無參數(shù)就是完全阻塞主線程,等待線程執(zhí)行完 有參數(shù)就是說,# 在主線程等待一秒后就不阻塞線程了,繼續(xù)執(zhí)行主線程,這里的意思是一秒鐘開一個線程# 不能再thread start之前調(diào)用join(), 因?yàn)閖oin() 是線程運(yùn)行時調(diào)度 for t in tsk:t.start()t.join(1) print 'All thread OK,maybe not ' outFile.close()
問題解答
回答1:提示說tryMsgcode()方法接受2個參數(shù)但是你一個都沒傳
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.3. 刷新頁面出現(xiàn)彈框4. javascript - 前端開發(fā) 本地靜態(tài)文件頻繁修改,預(yù)覽時的緩存怎么解決?5. javascript - 怎么看網(wǎng)站用了什么技術(shù)框架?6. javascript - 編程,算法的問題7. javascript - 請教空白文本節(jié)點(diǎn)的問題8. PC 手機(jī)兼容的 編輯器9. 關(guān)于Android權(quán)限的獲取問題,大家遇到過這樣的情況嘛?10. css - 關(guān)于border-image
