gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:03:01 30 4
gpt4 key购买 nike

我尝试使用 python 将文件附加到邮件中。
代码:

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 我收到错误:socket.gaierror: [Errno 11001] getaddrinfo failed

完整的错误信息:
 File "C:\Python27\lib\smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed

最佳答案

我确信当您从代理后面工作时会出现 gaierror。

关于python - socket.gaierror : [Errno 11001] getaddrinfo failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18400208/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com