python的postcommit hook出错

2024-05-07 05:55:12 发布

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

我正在编写一个python脚本,我的mac笔记本电脑工作正常,但Windows收到以下错误:

Traceback (most recent call last):
File "mail.py", line 16, in <module>
gmail = smtplib.SMTP("smtp.gmail.com", 587)
File "c:\Python34\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "c:\Python34\lib\smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "c:\Python34\lib\smtplib.py", line 292, in _get_socket
self.source_address)
File "c:\Python34\lib\socket.py", line 494, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "c:\Python34\lib\socket.py", line 533, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed
[bugfix/IM0597695 6ddbc68] test3
1 file changed, 1 deletion(-)

还有我的python脚本和虚拟数据:

import smtplib
from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText
user = ("blabla@gmail.com")
password = ("1234")
#header mail
remitente = ("blabla@gmail.com")
destinatarios = ["<blabla@blabla.com>"]
asunto = ("Hey se hizo un nuevo commit")
mensaje = ("Latest version")
#Servidor Smtp & Puerto Smtp
gmail = smtplib.SMTP("smtp.gmail.com", 587) 
# Protocolo de sifrado de datos utilizado por gmail:
gmail.starttls()
# Credenciales del usuario:
gmail.login(user, password)
# Muestra la depuracion (a medida que se envia el email) 
gmail.set_debuglevel(1) # 1 = True
#Cabecera de email
header = MIMEMultipart()
header['Subject'] = asunto
header['From'] = remitente
header['To'] = ",".join(destinatarios)
mensaje = MIMEText(mensaje, 'plain') # Tipo de mensaje (HTML) (Plain)
header.attach(mensaje) # Agregamos el mensaje a la cabecera
#Enviar email
gmail.sendmail(remitente, destinatarios, header.as_string())
#gmail la conexión SMTP
gmail.quit()

我做错什么了??有什么线索吗?你知道吗

谢谢你。你知道吗


Tags: inpyselfcomhostemaillibline