1

我在 Windows 7 和 Python 2.7 上安装了 IE 9。当我使用 Firefox 作为驱动程序时,此代码运行良好,但在 IE 中它会在几秒钟后崩溃。我想知道它是否在 while 循环期间达到了高 CPU 状态?在编写好的 while/wait 循环方面,我是个菜鸟。

def text_from_gmail(username, password, to_user, pattern):
    gmail = PyGmail('imap.gmail.com')
    gmail.login(username, password)

    #find the id of the confirmation message
    sec_waiting = 0
    msg_uid = ['']
    sleep_period = 10  # seconds to wait between Gmail searches
    while msg_uid == ['']:  # wait until message list from server isn't empty
        gmail.m.select('[Gmail]/All Mail')
        resp, msg_uid = gmail.m.search(None, 'To', to_user)
        if(msg_uid != ['']):
            break  # don't sleep if the message was found quickly
        time.sleep(sleep_period)  # pause between checks
        sec_waiting += sleep_period
        if sec_waiting >= 300:  # 5 minute timeout
            assert False  # fail the test if timeout elapses

    # extract the confirmation link from the message
    # it's a multi-part MIME, so we have to grab the attachment and decode it
    typ, msg_data = gmail.m.fetch(msg_uid[0], '(RFC822)')
    gmail.logout()
    email_body = msg_data[0][1]
    mail = email.message_from_string(email_body)
    body = ""
    for part in mail.walk():
        if(part.get_content_type() == 'text/plain'):
            body = part.get_payload(decode=True)

    link = re.findall(pattern, body)
    return link
4

1 回答 1

0

我认为它试图访问格式错误的 URL。我在它周围放了一个 str() driver.web.get(str(confirm_link)) 并且它现在没有崩溃。

于 2013-03-09T22:25:24.977 回答