python - 无法使用命令提示符执行 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()
解决方案
推荐阅读
- google-colaboratory - Google Colab:运行所有单元格,直到当前单元格
- angular - 未捕获的类型错误:无法在 registerNgModuleType 读取未定义的属性“id”-角度 PWA
- javascript - 如何优化 JS 中的拉推元素?
- python - 为什么我的 Scrapy 规则 (LinkExtractor) 不起作用?
- excel - 如何删除重复项,保存最新条目并将数据复制到剩余条目?
- python - 在 Python 3 中更新 Sqlite3
- bash - Shell BASH---文件提取时出现SHA256 Hash Collisions
- three.js - Thee.js Material 接收阴影有奇怪的效果
- java - 用于显示它是否生病的布尔随机数
- angular - 将 MatInput 元素与 @ViewChild 一起使用,结果变量在运行规范时不可用