发送邮件错误python

2024-09-28 21:24:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试thaat发送邮件的脚本时遇到以下错误

    import urllib.request
    import re
    import smtplib
    from email.mime.text import MIMEText
    from bs4 import BeautifulSoup
    page=urllib.request.urlopen("http://www.crummy.com/")
    soup=BeautifulSoup(page)
    v=soup.findAll('a',href=re.compile('http://www.crummy.com/2012/07/24/0'))
    for link in v:

      w=link.get('href')


    server = smtplib.SMTP( "smtp.gmail.com", 587 )
    server.starttls()
    server.login( 'xxxxxxxxxxx', 'xxxxxxx' )
    server.sendmail( 'xxxxxxxxx', 'xxxxxxxxx', "bonus question is up" )

Traceback (most recent call last): File "C:\Python32\bonus", line 14,
in server = smtplib.SMTP( "smtp.gmail.com", 587 ) File
"C:\Python32\lib\smtplib.py", line 259, in init File "C:\Python32\lib\smtplib.py", line 319, in connect self.sock = self._get_socket(host, port, self.timeout) File "C:\Python32 \lib\smtplib.py", line 294, in _get_socket return socket.create_connection((host, port), timeout) File "C:\Python32\lib\socket.py", line 386, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11004] getaddrinfo failed plse advice on the best way to go round it


Tags: inpyimportselfcomhostgetserver
1条回答
网友
1楼 · 发布于 2024-09-28 21:24:52

getaddrinfo函数有以下用途:

The getaddrinfo function provides protocol-independent translation from an ANSI host name to an address.

如果失败,则意味着它无法将给定的主机名转换为相应的地址。它实际上是在做一个DNS查询。

getaddrinfo返回的错误号“11004”与此消息关联:

Valid name, no data record of requested type. The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable.

似乎您正在查找的名称没有与之关联的正确数据。

你确定你的网址是正确的吗?

链接:

getaddrinfohttp://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx

WinSock错误代码:http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx

相关问题 更多 >