Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

python - socket.gaierror: [Errno 11001] getaddrinfo failed

I have tried to attached a file to the mail using python. Code:

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from smtplib import SMTPException


def send_Email():
    file1="abc.txt"
    message = "Test mail"
    msg = MIMEMultipart()

    msg.attach(MIMEText(file(file1).read()))

    try:
        smtpObj = smtplib.SMTP('smtp server name',port)
        smtpObj.sendmail(sender, EmailId, message, msg.as_string() )
        print "Successfully sent email"
    except SMTPException:
        print "Error: unable to send email"

Bt I have get the error: socket.gaierror: [Errno 11001] getaddrinfo failed

full error message:

 File "C:Python27libsmtplib.py", line 249, in __init__
    (code, msg) = self.connect(host, port)
  File "C:Python27libsmtplib.py", line 309, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:Python27libsmtplib.py", line 284, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "C:Python27libsocket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I know for sure that gaierror comes up when you are working from behind proxy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...