D
D
Dmitry2021-11-09 19:37:37
Python
Dmitry, 2021-11-09 19:37:37

How to handle dictionary with smtplib.SMTPRecipientsRefused (Python3) error?

The script sends letters, and does processing if everything is ok, then returns the address, if not, then the error and the address, but the error has the format smtplib.SMTPRecipientsRefused({'[email protected]': (550, b'non-local recipient verification failed' ))
class type 'smtplib.SMTPRecipientsRefused'
output {'[email protected]': (550, b'non-local recipient verification failed')}
but how to handle this error so that it outputs it as a dictionary type so that you can work with it
error handling code:

try:
        mailsender.sendmail(LOGIN, RECIPIENT, msg.as_string())
        # list_mail.append(RECIPIENT)
        # print('письмо отправлено', RECIPIENT)
        mailsender.quit()
        return RECIPIENT
    except BaseException as err:
        # list_mail.append(err)
        print(type(err))
        pass
        mailsender.quit()
        return f'{err} {RECIPIENT}'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-11-11
@ipatov_dn

I decided this way: I presented everything as a string and with the help of regular expressions, I put everything in ( ) into a variable as an error code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question