0
 try:
       es1,es2 = es_connection()# call to es_connection function
       path = " "
       for files in os.listdir(path):
        try:
          if files.endswith('.json'):
           name = files.strip(".json")
           json_path = os.path.join(path, files)
           with open(json_path, "r") as json_file:
               action to be performed
        except Exception as ex:
          print(ex)
          pass
      #except2
      except Exception as ex:
        subject = "Unable to ping ES"
        send_mail_parameters(subject) # call to sendmail function

I have following 2 queries

  1. I wanted to connect to ES and execute query in try block, if unable to connect to ES need to send mail (code in except2 block) but what is happening is even after code in try is executed, without executing except block mail is sent.

Need help to find out why is this happening

  1. is my pass statement indented right to continue for loop?
div
  • 23
  • 5
  • I don't understand what you're asking in 1, but for 2, note that `pass` does literally nothing. It's a noop placeholder. Are you thinking of `continue`? Neither should be necessary there though. – Carcigenicate Dec 15 '20 at 16:11
  • regarding 1, without my except#2 block getting executed i am getting action expected out of it (ie email sent) – div Dec 15 '20 at 16:32
  • regarding 2,i want to continue for loop even if it is unable to read json.Continue leaves the loop and starts next iteration,but what i want is if error occurs in 30th json file it should continue with 31st json file https://stackoverflow.com/questions/9483979/is-there-a-difference-between-continue-and-pass-in-a-for-loop-in-python/36952166#:~:text=Yes%2C%20there%20is%20a%20difference,remainder%20or%20the%20loop%20body.&text=continue%20will%20jump%20back%20to,pass%20will%20continue%20processing. – div Dec 15 '20 at 16:41

0 Answers0