简体   繁体   中英

Unable to connect to SQL Server with Kerberos when transformers library is installed

I'm trying to connect to an mssql database using Kerberos authentication in Python. When my anaconda environment just has pyodbc installed, I can connect and send queries to the database. But when I add huggingface's transformer's library to the environment, I get the following error:

Error: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No credentials were supplied, or the credentials were unavailable or inaccessible. No Kerberos credentials available: No KCM server found (458752) (SQLDriverConnect)')

An example function that works without the transformer's library installed is

import pyodbc
def pyodbc_query(query):

    cnxn = pyodbc.connect(
        Trusted_Connection='Yes',
        Driver='{/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1}',
        Server='servername',
        Database='database'
    )
    cursor = cnxn.cursor()
    cursor.execute(query)
    result = cursor.fetchall()

    return result

I've also tried using sqlalchemy instead of pyodbc, with the same results. My pyodbc version is 4.0.35 and my transfromers version is 4.26.0. Has anyone had the same problem?

In case anyone else stumbles on this: The issue is that transformers downloads the library krb5 as a dependency, and this package can mess up the system's Kerberos system configuration. You can uninstall just krb5 with conda remove krb5 --force -y if you don't need it for anything else. More information is available in a github issue: https://github.com/ContinuumIO/anaconda-issues/issues/10772

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM