1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Connect with Oracle Database via LDAP Authentication

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am using python's pyodbc library to connect with the Oracle Database. The authentication to my non-prod servers were set-up as Basic Authentication so my connection string worked well.

    It was tough to understand and set up the right drivers initially, But then did manage to get through. Here is what the code looks like for connection and worked well for my other servers.

    import textwrap
    import pyodbc
    connection_string = textwrap.dedent('''Driver={driver};
    DBQ={hostname}:{port}/{sid};
    UID={username};
    PWD={password};
    Connection Timeout=30;
    Trusted_Connection="yes"
    '''.format(driver = 'Oracle in instantclient_11_2',
    hostname = <hostname>,
    port = <port>,
    sid = <sid>,
    username = <username>,
    password = <passwd>
    ))

    connection = pyodbc.connect(connection_string)


    To my surprise PROD is authenticated via LDAP only. To which I have the LDAP Server, Context, and DB Service along with the credentials.

    I tried creating my connection string as

    connection_string = textwrap.dedent('''Driver={driver};
    DBQ={hostname}:{port}/{sid};
    UID={username};
    PWD={password};
    Connection Timeout=30;
    Authentication=LDAP;
    Trusted_Connection="yes"
    '''.format(driver = 'Oracle in instantclient_11_2',
    hostname = <ldap_server>,
    port = 389,
    sid = <db_service>,
    username = <username>,
    password = <passwd>
    ))


    To which I was not surprised to know it wont work. Tried going through many links but could not get through. Has anyone tried this before or please let me know what I must be missing.

    I could definitely connect in SQL Developer using the LDAP Authentication. And since TNS Listener is not configured on this server I cannot use Basic Authentication to connect.

    And help would be welcome on this.

    Continue reading...

Compartilhe esta Página