python-3.xazure-functionsconnection-stringappsettings

How to access connection string with python


I have this local.settings.json in my local Azure function (Timer trigger)

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    .
    .
    .
  },
  "ConnectionStrings": {
    "sql_server": "valid connection string"
  }
}

I managed to access the connection string locally using: conn = os.environ["ConnectionStrings:sql_server"] and my code runs okay.

But, when I deploy I get 'Failure Exception: KeyError: 'sql_server' [...] getitem raise KeyError(key) from None'.

I tried to execute in portal changing that line to: conn = os.environ["sql_server"] But nothing changed.

Does anyone know how I can call this method on Azure Web?


Solution

  • enter image description here

    • SQLServer: SQLCONNSTR_
    • MySQL: MYSQLCONNSTR_
    • SQLAzure: SQLAZURECONNSTR_
    • Custom: CUSTOMCONNSTR_
    • PostgreSQL: POSTGRESQLCONNSTR_
    • Notification Hub: NOTIFICATIONHUBCONNSTR_
    • Service Bus: SERVICEBUSCONNSTR_
    • Event Hub: EVENTHUBCONNSTR_
    • Document Db: DOCDBCONNSTR_
    • Redis Cache: REDISCACHECONNSTR_

    enter image description here