国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)

瀏覽:161日期:2022-08-15 08:22:21

問題描述

# -*- 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 = [] # 創(chuàng)建線程池 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)# 記住這里要將文件重新移到文件首,不然就會出現只執(zhí)行外層循環(huán)的第一條,因為內層在# 迭代之后(readlines()是迭代器的形式,迭代一次后文件指針就指到文件尾了,迭代器# 也是end了)第二次就沒有password 在 fPass中,也就是說 for password in fPass.readlines():# 為空,所以這里的內層循環(huán)就不會被執(zhí)行了,因此也就是迭代器清零的問題(C ++ itertor 常有)# join()無參數就是完全阻塞主線程,等待線程執(zhí)行完 有參數就是說,# 在主線程等待一秒后就不阻塞線程了,繼續(xù)執(zhí)行主線程,這里的意思是一秒鐘開一個線程# 不能再thread start之前調用join(), 因為join() 是線程運行時調度 for t in tsk:t.start()t.join(1) print 'All thread OK,maybe not ' outFile.close()

python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)

問題解答

回答1:

提示說tryMsgcode()方法接受2個參數但是你一個都沒傳

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 曲周县| 安龙县| 喀喇沁旗| 娱乐| 孝义市| 甘孜| 石台县| 崇文区| 丰镇市| 沙雅县| 镇江市| 中西区| 浮梁县| 新兴县| 新密市| 阿城市| 赞皇县| 同德县| 镇远县| 探索| 营口市| 通道| 伊通| 定襄县| 紫金县| 三门县| 阳城县| 奇台县| 宝山区| 屯门区| 蚌埠市| 云安县| 青田县| 通河县| 张家口市| 贵定县| 抚远县| 东安县| 始兴县| 石景山区| 五大连池市|