python错误登录,甚至从gmail启用imap

python错误登录,甚至从gmail启用imap,python,python-3.x,gmail,imap,Python,Python 3.x,Gmail,Imap,我试图在python中使用imap,但每次都会出错,我按照所有步骤从gmail激活imap并解锁captcha,但在第一次运行后,我收到了此错误,请立即提供帮助,谢谢 raise self.error(dat[-1]) imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)' gmail发布后,我收到了来自gmail的Alert security,来自imap的所有访问都被阻止 使用的代码` # Import

我试图在python中使用imap,但每次都会出错,我按照所有步骤从gmail激活imap并解锁captcha,但在第一次运行后,我收到了此错误,请立即提供帮助,谢谢

raise self.error(dat[-1])
imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
gmail发布后,我收到了来自gmail的Alert security,来自imap的所有访问都被阻止

使用的代码`

 # Importing libraries 
import imaplib, email 

    user = 'USER_EMAIL_ADDRESS'
    password = 'USER_PASSWORD'
    imap_url = 'imap.gmail.com'
    
    # Function to get email content part i.e its body part 
    def get_body(msg): 
        if msg.is_multipart(): 
            return get_body(msg.get_payload(0)) 
        else: 
            return msg.get_payload(None, True) 
    
    # Function to search for a key value pair 
    def search(key, value, con): 
        result, data = con.search(None, key, '"{}"'.format(value)) 
        return data 
    
    # Function to get the list of emails under this label 
    def get_emails(result_bytes): 
        msgs = [] # all the email data are pushed inside an array 
        for num in result_bytes[0].split(): 
            typ, data = con.fetch(num, '(RFC822)') 
            msgs.append(data) 
    
        return msgs 
    
    # this is done to make SSL connnection with GMAIL 
    con = imaplib.IMAP4_SSL(imap_url) 
    
    # logging the user in 
    con.login(user, password) 
    
    # calling function to check for email under this label 
    con.select('Inbox') 
    
    # fetching emails from this user "tu**h*****1@gmail.com" 
    msgs = get_emails(search('FROM', 'MY_ANOTHER_GMAIL_ADDRESS', con)) 
    
    # Uncomment this to see what actually comes as data 
    # print(msgs) 
    
    
    # Finding the required content from our msgs 
    # User can make custom changes in this part to 
    # fetch the required content he / she needs 
    
    # printing them by the order they are displayed in your gmail 
    for msg in msgs[::-1]: 
        for sent in msg: 
            if type(sent) is tuple: 
    
                # encoding set as utf-8 
                content = str(sent[1], 'utf-8') 
                data = str(content) 
    
                # Handling errors related to unicodenecode 
                try: 
                    indexstart = data.find("ltr") 
                    data2 = data[indexstart + 5: len(data)] 
                    indexend = data2.find("</div>") 
    
                    # printtng the required content which we need 
                    # to extract from our email i.e our body 
                    print(data2[0: indexend]) 
    
                except UnicodeEncodeError as e: 
                    pass


'

如果您是在云主机或类似设备上运行此功能,那么如果不实现OAuth身份验证或特定于应用程序的密码,此功能可能永远无法工作


谷歌的帐户安全设置似乎只允许可能的最终用户主机登录。如果您在您的个人计算机上运行它,并且您也从中登录,那么您必须激活简化的安全设置,生成特定于应用程序的密码,或者实现OAuth。

如果您在云主机或类似主机上运行它,如果不实现OAuth或特定于应用程序的密码,这可能永远不会起作用。谷歌的帐户安全设置似乎只允许可能的最终用户主机登录。如果您在您的个人计算机上运行它,您也可以从中登录,则必须激活降低的安全设置,生成特定于应用程序的密码,或者实现OAuth。它是在激活降低安全性后修复的谢谢soo mucch bro@Max您帮助了我…因此必须首先激活imap并解锁catpcha和降低安全性设置…我将更改为一个答案,因为这对您有帮助。@Max您活该这是丢失的一步。。。