簡體   English   中英

(tkinter) ConnectionRefusedError: [WinError 10061] 由於目標機器主動拒絕,無法建立連接

[英](tkinter) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

我嘗試使用不同的端口並在互聯網上找到解決方案,但我仍然無法修復它。 我嘗試將 localhost 更改為 127.0.0.1 並嘗試將端口號更改為所有類型的值,但仍然無法正常工作。 非常感謝您的幫助。

import tkinter
import smtplib
import socket

from email.parser import Parser

smtp = smtplib.SMTP

user = ""
password = ""

def connect():
    print(msg_entry.get())

    smtp = smtplib.SMTP("localhost", 587)
    #smtp.login(user,password)
    smtp.sendmail(from_entry.get(), to_entry.get(), msg_entry.get())
    smtp.quit()

app = tkinter.Tk()
app.title("test")


to_label = tkinter.Label(app,text="To:")
to_entry = tkinter.Entry(app)

from_label = tkinter.Label(app,text="From:")
from_entry = tkinter.Entry(app)

send_button = tkinter.Button(app,text="send",command=connect)

msg_label = tkinter.Label(app,text="Email:")
msg_entry = tkinter.Entry(app,width=50)
#pack(add) the widget to the app.
to_label.pack()
to_entry.pack()

from_label.pack()
from_entry.pack()

msg_label.pack()
msg_entry.pack()

send_button.pack()

#draw the window, have this at the end
app.mainloop()

每當我單擊發送時,我都會收到錯誤消息:

    Traceback (most recent call last):
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:/Users/ADMIN/PycharmProjects/CourseOutcome3/EmailTransmitter-DAMPAC.py", line 15, in connect
    smtp = smtplib.SMTP("localhost", 587)
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 308, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\socket.py", line 808, in create_connection
    raise err
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python38\lib\socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

您需要在localhost上有一個服務器才能使其工作,我推薦PaperCut ,您也可能想查看我的這篇關於如何創建基本 smtp 郵件服務器的帖子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM