python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)
阿神
阿神 2017-04-18 10:29:49
0
1
609
# -*- coding: utf-8 -*-
import urllib2
import urllib
import httplib
import threading
import 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'
    return


outFile = 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个参数
但是你一个都没传

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!