WinError 10060 A connection attempt failed because the connected party did not properly respond

血红的双手。 提交于 2020-01-01 19:39:47

问题


I am trying to verify emails by sending requests to SMTP servers. When I test in Linux, it works for 90% of emails. When I test in Windows, I did some analysis and like for 79% of emails will show the WinError10060 problem.

I tried using VPN, proxies and even turning off the firewall but the same problem will appear:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Could this be from the firewall in the router or the internet provider blocking the port? But in the mean time, for 21% of emails I get answers like 250, 550 etc.

Here's the code:

        for email in rows:
            email = email[0]
            start = time.time()

            if(email[-3:] == 'png'):
                pass
            else:
                counter += 1
                maildomain = email.split("@")[-1]
                nstoken = "mail exchanger = "
                mailserver = ""
                mailservers = []

                # Checking for domain names
                # Command: nslookup -type=mx [mx server here]
                plines = os.popen("nslookup -type=mx " + maildomain).readlines()
                for pline in plines:
                    if nstoken in pline:
                        mailserver = pline.split(nstoken)[1].strip()
                        # No need this line in Windows environment
                        mailserver = mailserver.split(" ")[-1]
                        mailservers.append(mailserver)

                invalid_emails = [550, 551, 553]
                cannot_verify_emails = [450, 451, 452]

                if mailservers == []:
                    email_result = "Invalid"
                    code_result = 000
                    print("No mail servers found")

                else:
                    i = mailservers[0]
                    print("i: ", mailservers[0])
                    try:
                        # timeout = 10
                        # socket.setdefaulttimeout(timeout)
                        s = smtplib.SMTP(i)

                        # Identifying to an ESMTP server
                        # Command helo hi / ehlo hi
                        rep1 = s.ehlo()
                        print("rep1: ", rep1)

                        if rep1[0] == 250:
                            rep2 = s.mail("grencir1982@teleworm.us")
                            print("rep2: ", rep2)
                            if rep2[0] == 250:
                                rep3 = s.rcpt(email)
                                print("rep3: ", rep3)
                                if rep3[0] == 250:
                                    print(email, " is valid, " + str(rep3[0]))
                                    email_result = "Valid"
                                elif rep3[0] in cannot_verify_emails:
                                    print(email, " verification not allowed" + str(rep3[0]))
                                    email_result = "Server disallows verification or user mailbox is currently unavailable"
                                elif rep3[0] in invalid_emails:
                                    print(email, " doesn't exist " + str(rep3[0]))
                                    email_result = "Invalid"
                                else:
                                    print(email, " response, " + str(rep3[0]))
                                    email_result = "Other response"
                                code_result = str(rep3[0])
                            else:
                                print("rep2: s.rcpt not working")
                                email_result = "Other response"
                        else:
                            print("rep1: s.mail not working")
                            email_result = "Other response: Probably IP Blacklisted"
                        s.quit()
                    except socket.timeout:
                        email_result = "Socket Timeout Exception"
                        code_result = 000
                        print("Socket Timeout")
                        pass
                    except Exception as e:
                        email_result = str(e)
                        code_result = 000
                        print(e)

来源:https://stackoverflow.com/questions/51378463/winerror-10060-a-connection-attempt-failed-because-the-connected-party-did-not-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!