-1

I want to understand how to return to or repeat a set code in case an error occurs.

For example:

import smtpd    

LoginE = input("What is the email you will be using? \n")
LoginP = input("what is the password of the email you will using? \n")
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login( LoginE , LoginP)

I have tried to use the try function but it still will crash and tell me I have an error.

2

1 Answer 1

1

You can just wrap the code with a while block:

import smtpd  
while True:
   LoginE = input("What is the email you will be using? \n")
   LoginP = input("what is the password of the email you will using? \n")
   try: 
      server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
      server.login( LoginE , LoginP)
      break
   except: # you can put any error here
      pass
Sign up to request clarification or add additional context in comments.

2 Comments

true will throw an exception, I think you meant True
Yes, I meant so. I wrote it directly to the answer so it was prone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.