Błąd "module 'httpcore' has no attribute 'CloseError'"

0

Oto błąd - wie ktoś jak go naprawić?

CloseError = httpcore.CloseError

AttributeError: module 'httpcore' has no attribute 'CloseError'

Kod:

import smtplib
import imaplib
import email
from email.mime.text import MIMEText
import dns.resolver

def is_valid_email(email):
    try:
        domain = email.split('@')[1]
        records = dns.resolver.resolve(domain, 'MX')
        if len(records) > 0:
            return True
        else:
            return False
    except:
        return False

def get_smtp_imap_servers(provider):
    servers = {
        "gmail": ("smtp.gmail.com", "imap.gmail.com"),
        "outlook": ("smtp.office365.com", "outlook.office365.com"),
        "thunderbird": ("smtp.thunderbird.com", "imap.thunderbird.com")
    }
    return servers.get(provider.lower())

selected_provider = input("Podaj dostawcę poczty (gmail/outlook/thunderbird): ")
smtp_server, imap_server = get_smtp_imap_servers(selected_provider)

receiver_email = input("Podaj adres email odbiorcy: ")
if not is_valid_email(receiver_email):
    print("Podany adres email odbiorcy jest nieprawidłowy lub nie istnieje. Spróbuj ponownie.")

sender_email = input("Wprowadź swój adres email: ")
if not is_valid_email(sender_email):
    print("Twój adres jaki podałeś jest nieprawidłowy lub nie istnieje. Spróbuj ponownie.")

sender_password = input("Wprowadź swoje hasło: ")
company = input("Podaj nazwę firmy: ")
goal = input("Podaj cel rozmowy: ")
subject = f"Wdrożenie firmy {company}"

def main():

    input_text = (
        f"Napisz email, w którym twoim celem jest {goal}. "
        f"Jeśli twój cel to zachęcenie klienta do kupna produktu itp. firmy {company}, "
        "pisz email w którym powiesz o tej firmie, co ona robi itp. Zachęcisz do zakupu. "
        "Wymień jeszcze parę emaili, w których zachęcisz do zakupu. "
        f"Jak klient już będzie lekko przekonany, to wyślij mu prezentację całej firmy, jej zalety i sposób wdrożenia firmy {company}. "
        f"Po tych krokach pożegnaj się z klientem i podaj mu adres email oraz numer telefonu firmy {company}. "
        "Przedstaw się jako Marcin, do dzieła!"
    )

    last_email_id = 0

    message = input("Napisz swoją wiadomość: ")
    send_email(sender_email, sender_password, receiver_email, subject, message, smtp_server)
    print("Wiadomość wysłana!")

    last_email_id = 0

    while True:
        print("Czekam na odpowiedź...")
        last_email_id = read_emails(sender_email, sender_password, receiver_email, last_email_id, imap_server)

def send_email(sender_email, app_password, receiver_email, subject, message, smtp_server):
    msg = MIMEText(message)
    msg["From"] = sender_email
    msg["To"] = receiver_email
    msg["Subject"] = subject

    server = smtplib.SMTP(smtp_server, 587)
    server.starttls()
    try:
        server.login(sender_email, app_password)
    except smtplib.SMTPAuthenticationError:
        print("Błędne hasło. Spróbuj ponownie.")
        return
    server.sendmail(sender_email, receiver_email, msg.as_string())
    server.quit()

def read_emails(sender_email, sender_password, receiver_email, last_email_id, imap_server):
    mail = imaplib.IMAP4_SSL(imap_server)
    try:
        mail.login(sender_email, sender_password)
    except imaplib.IMAP4.error:
        print("Błędne hasło. Spróbuj ponownie.")
        return last_email_id
    mail.select("inbox")

    _, data = mail.search(None, f"FROM {receiver_email} UNSEEN")
    email_ids = data[0].split()

    for email_id in email_ids:
        if int(email_id) > last_email_id:
            _, msg_data = mail.fetch(email_id, "(RFC822)")
            raw_email = msg_data[0][1]
            msg = email.message_from_bytes(raw_email)
            print("From:", msg["From"])
            print("Date:", msg["Date"])
            print("Subject:", msg["Subject"])
            print("Body:")
            if msg.is_multipart():
                for part in msg.walk():
                    if part.get_content_type() == "text/plain":
                        print(part.get_payload(decode=True).decode("utf-8"))
                        response = input("Odpowiedz na email: ")
                        send_email(sender_email, sender_password, msg["From"], subject, response, smtp_server)
                        print("Wiadomość wysłana!")
                        break
            else:
                print(msg.get_payload(decode=True).decode("utf-8"))
            print("=" * 50)
            last_email_id = int(email_id)

    mail.logout()
    return last_email_id

if __name__ == "__main__":
    main()
4

Sformatuj kod, podaj cały stacktrace, co mówi debugger?

1 użytkowników online, w tym zalogowanych: 0, gości: 1