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. mysql - java ResultSetMetaData 獲取中文別名亂碼2. css - ionic中的柵格布局如何讓文字內容多少不同的每一列中的內容都能垂直居中?3. javascript - 關于ajax的疑問?4. php自學從哪里開始?5. html - eclipse 標簽錯誤6. css3 - 手機網頁中用css寫1px的描邊,為什么需要加一句overflow:hidden才能真正顯示1px?7. javascript - js里首尾相接輪播的原理是什么?8. javascript - 如果所有請求都放到actions 里面,那拿到的數據應該 放在哪里,state 還是vue實例里面的data?9. phpstady在win10上運行10. python - 管道符和ssh傳文件
