title: Prompt user to retry password when unsuccessful in cx_Oracle connect method
body: <p>I ma using the cx_Oracle module in python to connect and query an oracle database. </p>
  
  <pre><code>import cx_Oracle
  </code></pre>
  
  <p>I have built a tkinter widget so the user can be prompted for their username and password which, in turn, will get passed into the user/password portion of the connect method:</p>
  
  <pre><code>username = 'user'
  password = 'password'
  db = cx_Oracle.connect('{0}/{1}@//random.company:1234/db1.company.com'.format(username, password))
  </code></pre>
  
  <p>This all works well when the user inputs their correct username and password in the first try however when they don't, I need some logic to iteratively re-try their username and/or password. </p>
  
  <p>The error that is thrown when the wrong credentials are entered is this:</p>
  
  <blockquote>
    <p>cx_Oracle.DatabaseError: ORA-01017: invalid username/password; logon
    denied</p>
  </blockquote>
  
  <p>I've been digging around the interweb for a while now and I can't really seem to find something that works for me. It seems like a lot of the things I've come across involves checking username and passwords against a known dictionary or something along those lines. I don't have the luxury of doing that. I'm probably at a point where I am over thinking this anyways, so I wanted to post up. I feel like it's just some sort of easy 'while' loop I need. Something like:</p>
  
  <pre><code>while connection_throws_error_:
      keep_trying_to_log_in
  </code></pre>
  
  <p>Here is my general code:</p>
  
  <pre><code>import Tkinter
  from Tkinter import *
  import cx_Oracle, pprint
  
  master = Tk()
  Label(master, text="Username").grid(row=0)
  Label(master, text="Password").grid(row=1)
  
  e1 = Entry(master)
  e2 = Entry(master, fg = 'red', show="*")
  
  e1.grid(row=0, column=1)
  e2.grid(row=1, column=1)
  
  Button(master, text='Login', command=master.quit).grid(row=3, column=1, sticky=W, pady=4)
  
  master.title("MEMPRD Login")
  master.mainloop()
  
  # This is where I need to iteratively prompt user to enter crentials if they are incorrect.
  db = cx_Oracle.connect('{0}/{1}@//random.company:1234/db1.company.com'.format(e1.get(), e2.get())
  </code></pre>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <p>Thanks to Alex below, I've used his code, made a few customizations for my own use and it works. Here's the working code:</p>
  
  <pre><code>master = Tk()
  Label(master, text="Username").grid(row=0)
  Label(master, text="Password").grid(row=1)
  
  e1 = Entry(master)
  e2 = Entry(master, fg = 'red', show="*")
  
  e1.grid(row=0, column=1)
  e2.grid(row=1, column=1)
  
  Button(master, text='Login', command=master.quit).grid(row=3, column=1, sticky=W, pady=4)
  #Button(master, text='Show', command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
  
  
  
  master.title("Login")
  master.mainloop()
  
  #show_entry_fields()
  
  
  
  print e1.get()
  print e2.get()
  
  while True:
      try:
          db = cx_Oracle.connect('{0}/{1}@//random.company:1234/db1.company.com'.format(e1.get(), e2.get())
      except cx_Oracle.DatabaseError as e:
          error, = e.args
          if error.code == 1017:
              print('Please check your credentials.')
              e2.delete(0, 'end')
              master.mainloop()        
          else:        
              raise
      else:
          print 'success!'
          break
  </code></pre>