-2

In Azure I am using a python web application and using a system assigned managed identity to access an azure sql database. The code works fine locally.

The original code:

azure_credentials = identity.DefaultAzureCredential()
raw_token = azure_credentials.get_token(TOKEN_URL).token.encode("utf-16-le")

results in 2022-10-06T14:13:28.375074194Z [INFO azure.identity._credentials.chained] DefaultAzureCredential acquired a token from ManagedIdentityCredential 2022-10-06T14:13:29.630486437Z [2022-10-06 14:13:29 +0000] [87] [WARNING] Worker with pid 91 was terminated due to signal 11 2022-10-06T14:13:29.658152384Z [2022-10-06 14:13:29 +0000] [97] [INFO] Booting worker with pid: 97

Why does get_token cause the thread to terminate?

L_Daniels
  • 26
  • 3

1 Answers1

0

The pyodbc version had been updated from pyodbc ==4.0.32 to pyodbc ==4.0.34

The following code runs locally under 4.0.34 but terminates threads with no error messages when deployed to an azure web application.

credential = DefaultAzureCredential() # (Doesn't matter which credential)
token = credential.get_token("https://database.windows.net/.default").token.encode("UTF-16-LE")
token_struct = struct.pack(f'<I{len(token)}s', len(token), token)
SQL_COPT_SS_ACCESS_TOKEN = 1256
connString = f"Driver={{ODBC Driver 17 for SQL Server}};SERVER=myServer;DATABASE=myDatabase"
conn = pyodbc.connect(connString, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})
cursor = conn.cursor()
cursor.execute("Select * from users")

The solution is to stick with pyodbc 4.0.32 for now.

L_Daniels
  • 26
  • 3