首页 > 解决方案 > 无法使用命令提示符执行 python 文件。给出错误“此 python 中不包含 SSL 支持”

问题描述

我有 .py 文件,它只是发送带有 excel 附件的电子邮件。从 Visual Studio 代码中,它可以毫无问题地执行和交付文件。

但是,当我使用命令提示符执行此文件时,它给了我一个错误:“此 python 中不包含 SSL 支持”。

命令提示符以管理员身份打开。

那么它适用于 Visual Studio Code 但不适用于命令提示符的原因可能是什么

在此处输入图像描述

如果我在命令提示符下键入 python,这就是我看到的:

在此处输入图像描述

此外,如果我使用 Visual Studio Code 中的终端,它也可以工作。我可以看到“基础”环境已激活。那么这与它有关吗?

在此处输入图像描述

fromaddr = "from@email"
toaddr = "To@email" 
# instance of MIMEMultipart 
msg = MIMEMultipart() 
# storing the senders email address   
msg['From'] = fromaddr 
# storing the receivers email address  
msg['To'] = toaddr  
# storing the subject  
msg['Subject'] = "Sending Attachement"
# string to store the body of the mail 
body = "Hello, This is Test and my attached file" 
# attach the body with the msg instance 
msg.attach(MIMEText(body, 'plain')) 
# open the file to be sent  
filename = "ExpirationList.xlsx"
attachment = open('C:\\Users\\Folder\\ExpirationList.xlsx',mode = 'rb') #rb opens file in bytes mode, not in text mode 
# instance of MIMEBase and named as p 
p = MIMEBase('application', 'octet-stream') 
# To change the payload into encoded form 
p.set_payload((attachment).read())  
# encode into base64 
encoders.encode_base64(p) 

p.add_header('Content-Disposition', "attachment; filename= %s" % filename) 

# attach the instance 'p' to instance 'msg' 
msg.attach(p) 

# creates SMTP session 
s = smtplib.SMTP('1.1.1.1: 25') 

# start TLS for security 
s.starttls() 

# Authentication 
#s.login(fromaddr, "Password") 

# Converts the Multipart msg into a string 
text = msg.as_string() 

# sending the mail 
s.sendmail(fromaddr, toaddr, text) 

# terminating the session 
s.quit() 

标签: pythonsslsmtpstarttls

解决方案


推荐阅读