2012-09-19 87 views
1

試圖腳本時,我收到以下錯誤看過那部發送郵件發送郵件錯誤蟒蛇

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

回答

4

getaddrinfo功能有這個目的:

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

如果失敗就意味着它無法將您指定的主機名轉換爲相應的地址。它本質上是在做一個DNS查詢。

你的錯誤號返回「11004」通過getaddrinfo有與之關聯此消息:

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