Search code examples
cx-oraclepython-3.8oracle11gr2tnsnames

Getting "ORA-28000: the account is locked" while connecting from Python to Oracle


I have Python (3.8.3) and Oracle DB (11g Release 2 server) installed in my local system. Both of the software are working fine individually. I can run programs in python as well as I have tables created with data in Oracle DB which I am able to access through Oracle SQL Developer & SQL Plus. But when I am trying to connect Oracle DB from python I am getting error as account locked. I have installed and executed import cx_Oracle successfully. But I am getting error when I am trying to execute below code.

1. Local initialization method - connection = cx_Oracle.connect("oe/oracle@localhost:1522/orcl11g2")

2. Connecting through TNSNAMES.ORA - connection = cx_Oracle.connect("oe", "oracle", "orcl11g2")

Error -

Traceback (most recent call last): File "", line 1, in cx_Oracle.DatabaseError: ORA-28000: the account is locked

My TNS Details -

File location - D:\app\Admin\product\11.2.0\dbhome_2\NETWORK\ADMIN

ORCL11G2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL11G2) ) )

Please help me. Just let me know if you need to know anything more to guide me.


Solution

  • In SQL Developer or SQL*Plus, connect to the DB as a privileged user such as SYSTEM or SYS, e.g:

    sqlplus system/yourpassword@localhost:1522/orcl11g2
    

    Then run the SQL statement:

    alter user oe account unlock;