首页 > 解决方案 > Python脚本失败基于Web的功能

问题描述

这是我在stackoverflow上的第一篇文章,如果描述有点奇怪,很抱歉。我一直在尝试制作一个通过电子邮件(smtplib 模块)发送数据的 python 脚本,以及下载图像和文件等其他 Web 功能。它工作了很多次,但今天它突然停止工作。我尝试连接到另一个网络,运行不同的 WiFi 重置命令,但到目前为止没有任何效果。这些是我一直遇到的问题。是否有任何已知的修复程序不涉及每次重新启动我的机器?

更新:似乎代码仅在重新启动后一分钟前有效。

import smtplib, ssl
context = ssl.create_default_context()
print(-2)
with smtplib.SMTP_SSL("smtp.gmail.com", port, timeout=120, context=context) as server:
    print(0)
    server.login(self_mail, password)
    print(2)
    server.sendmail(self_mail, rec_email, dfjk)
    print(3)



def iget(link, name):
    img_data = requests.get(link).content
    with open(name, 'wb') as handler:
        handler.write(img_data)
iget(link, 'h.png')
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

标签: pythonsslsmtplib

解决方案


推荐阅读